Pre Merge pull request !376 from lianghengyuan/ExcelUtil

pull/376/MERGE
lianghengyuan 11 months ago committed by Gitee
commit e77e4f0448
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

@ -172,6 +172,11 @@ public class ExcelUtil<T>
*/
public String[] excludeFields;
/**
*
*/
private String[] showFields;
public ExcelUtil(Class<T> clazz)
{
this.clazz = clazz;
@ -258,7 +263,7 @@ public class ExcelUtil<T>
/**
* excellist
*
*
* @param is
* @return
*/
@ -283,7 +288,7 @@ public class ExcelUtil<T>
/**
* excellist
*
*
* @param is
* @param titleNum
* @return
@ -295,7 +300,7 @@ public class ExcelUtil<T>
/**
* excellist
*
*
* @param sheetName
* @param titleNum
* @param is
@ -445,6 +450,67 @@ public class ExcelUtil<T>
}
return list;
}
/**
* listexcel
*
* @param response
* @param list
* @param sheetName
* @param title
* @param showFields fieldName
* @return
*/
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName, String title, List<String> showFields)
{
this.showFields = showFields.toArray(new String[0]);
exportExcel(response, list, sheetName, title);
}
/**
* listexcel
*
* @param response
* @param list
* @param sheetName
* @param showFields fieldName
* @return
*/
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName,List<String> showFields)
{
this.showFields = showFields.toArray(new String[0]);
exportExcel(response, list, sheetName, StringUtils.EMPTY);
}
/**
* listexcel
*
* @param response
* @param list
* @param sheetName
* @param title
* @param showFields fieldName
* @return
*/
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName, String title, String[] showFields)
{
this.showFields = showFields;
exportExcel(response, list, sheetName, title);
}
/**
* listexcel
*
* @param response
* @param list
* @param sheetName
* @param showFields fieldName
* @return
*/
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName,String[] showFields)
{
this.showFields = showFields;
exportExcel(response, list, sheetName, StringUtils.EMPTY);
}
/**
* listexcel
@ -504,7 +570,7 @@ public class ExcelUtil<T>
/**
* listexcel
*
*
* @return
*/
public void exportExcel(HttpServletResponse response)
@ -566,7 +632,7 @@ public class ExcelUtil<T>
/**
* excel
*
*
* @param index
* @param row
*/
@ -637,7 +703,7 @@ public class ExcelUtil<T>
/**
*
*
*
* @param wb
* @return
*/
@ -692,7 +758,7 @@ public class ExcelUtil<T>
/**
* Excel
*
*
* @param wb
* @return
*/
@ -728,7 +794,7 @@ public class ExcelUtil<T>
/**
* Excel
*
*
* @param wb
* @return
*/
@ -760,7 +826,7 @@ public class ExcelUtil<T>
/**
* Excel
*
*
* @param styles
* @param field
* @param excel
@ -822,7 +888,7 @@ public class ExcelUtil<T>
/**
*
*
*
* @param value
* @param attr
* @param cell
@ -981,7 +1047,7 @@ public class ExcelUtil<T>
/**
* POI XSSFSheet
*
*
* @param sheet
* @param textlist
* @param promptContent
@ -991,7 +1057,7 @@ public class ExcelUtil<T>
* @param endCol
*/
public void setPromptOrValidation(Sheet sheet, String[] textlist, String promptContent, int firstRow, int endRow,
int firstCol, int endCol)
int firstCol, int endCol)
{
DataValidationHelper helper = sheet.getDataValidationHelper();
DataValidationConstraint constraint = textlist.length > 0 ? helper.createExplicitListConstraint(textlist) : helper.createCustomConstraint("DD1");
@ -1018,7 +1084,7 @@ public class ExcelUtil<T>
/**
* ,.
*
*
* @param sheet sheet.
* @param textlist
* @param promptContent
@ -1070,7 +1136,7 @@ public class ExcelUtil<T>
/**
* 0=,1=,2=
*
*
* @param propertyValue
* @param converterExp
* @param separator
@ -1107,7 +1173,7 @@ public class ExcelUtil<T>
/**
* =0,=1,=2
*
*
* @param propertyValue
* @param converterExp
* @param separator
@ -1276,7 +1342,7 @@ public class ExcelUtil<T>
*/
public List<Object[]> getFields()
{
List<Object[]> fields = new ArrayList<Object[]>();
List<Object[]> fields = new ArrayList<>();
List<Field> tempFields = new ArrayList<>();
tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields()));
tempFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
@ -1284,36 +1350,38 @@ public class ExcelUtil<T>
{
if (!ArrayUtils.contains(this.excludeFields, field.getName()))
{
// 单注解
if (field.isAnnotationPresent(Excel.class))
{
Excel attr = field.getAnnotation(Excel.class);
if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
{
field.setAccessible(true);
fields.add(new Object[] { field, attr });
}
if (Collection.class.isAssignableFrom(field.getType()))
if (this.showFields != null && this.showFields.length != 0 && ArrayUtils.contains(this.showFields,field.getName())) {
// 单注解
if (field.isAnnotationPresent(Excel.class))
{
subMethod = getSubMethod(field.getName(), clazz);
ParameterizedType pt = (ParameterizedType) field.getGenericType();
Class<?> subClass = (Class<?>) pt.getActualTypeArguments()[0];
this.subFields = FieldUtils.getFieldsListWithAnnotation(subClass, Excel.class);
Excel attr = field.getAnnotation(Excel.class);
if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
{
field.setAccessible(true);
fields.add(new Object[] { field, attr });
}
if (Collection.class.isAssignableFrom(field.getType()))
{
subMethod = getSubMethod(field.getName(), clazz);
ParameterizedType pt = (ParameterizedType) field.getGenericType();
Class<?> subClass = (Class<?>) pt.getActualTypeArguments()[0];
this.subFields = FieldUtils.getFieldsListWithAnnotation(subClass, Excel.class);
}
}
}
// 多注解
if (field.isAnnotationPresent(Excels.class))
{
Excels attrs = field.getAnnotation(Excels.class);
Excel[] excels = attrs.value();
for (Excel attr : excels)
// 多注解
if (field.isAnnotationPresent(Excels.class))
{
if (!ArrayUtils.contains(this.excludeFields, field.getName() + "." + attr.targetAttr())
&& (attr != null && (attr.type() == Type.ALL || attr.type() == type)))
Excels attrs = field.getAnnotation(Excels.class);
Excel[] excels = attrs.value();
for (Excel attr : excels)
{
field.setAccessible(true);
fields.add(new Object[] { field, attr });
if (!ArrayUtils.contains(this.excludeFields, field.getName() + "." + attr.targetAttr())
&& (attr != null && (attr.type() == Type.ALL || attr.type() == type)))
{
field.setAccessible(true);
fields.add(new Object[] { field, attr });
}
}
}
}
@ -1349,7 +1417,7 @@ public class ExcelUtil<T>
/**
*
*
*
* @param sheetNo sheet
* @param index
*/
@ -1366,7 +1434,7 @@ public class ExcelUtil<T>
/**
*
*
*
* @param row
* @param column
* @return
@ -1426,7 +1494,7 @@ public class ExcelUtil<T>
/**
*
*
*
* @param row
* @return
*/
@ -1449,7 +1517,7 @@ public class ExcelUtil<T>
/**
*
*
*
* @param dateFormat
* @param val
* @return
@ -1515,7 +1583,7 @@ public class ExcelUtil<T>
/**
*
*
*
* @param name
* @param pojoClass
* @return

Loading…
Cancel
Save