Pre Merge pull request !376 from lianghengyuan/ExcelUtil

This commit is contained in:
lianghengyuan
2024-11-06 07:55:03 +00:00
committed by Gitee

View File

@@ -172,6 +172,11 @@ public class ExcelUtil<T>
*/
public String[] excludeFields;
/**
* 需要排除列属性
*/
private String[] showFields;
public ExcelUtil(Class<T> clazz)
{
this.clazz = clazz;
@@ -445,6 +450,67 @@ public class ExcelUtil<T>
}
return list;
}
/**
* 对list数据源将其里面的数据导入到excel表单
*
* @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);
}
/**
* 对list数据源将其里面的数据导入到excel表单
*
* @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);
}
/**
* 对list数据源将其里面的数据导入到excel表单
*
* @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);
}
/**
* 对list数据源将其里面的数据导入到excel表单
*
* @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);
}
/**
* 对list数据源将其里面的数据导入到excel表单
@@ -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,6 +1350,7 @@ public class ExcelUtil<T>
{
if (!ArrayUtils.contains(this.excludeFields, field.getName()))
{
if (this.showFields != null && this.showFields.length != 0 && ArrayUtils.contains(this.showFields,field.getName())) {
// 单注解
if (field.isAnnotationPresent(Excel.class))
{
@@ -1319,6 +1386,7 @@ public class ExcelUtil<T>
}
}
}
}
return fields;
}