update ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java.

新增一个 对list数据源将其里面的数据根据字段分组导入到excel表单的方法
This commit is contained in:
友人A 2022-04-13 03:34:49 +00:00 committed by Gitee
parent 035c326071
commit 323fbcbaae
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 31 additions and 0 deletions

View File

@ -429,6 +429,37 @@ public class ExcelUtil<T>
return exportExcel(); return exportExcel();
} }
/**
* 对list数据源将其里面的数据根据字段分组导入到excel表单
*
* @param list 导出数据集合
* @param title 标题
* @param fieldName 字段名称
* @return 结果
*/
public AjaxResult exportExcelGroupingByFieldName(List<T> list, String title, String fieldName) {
if (list == null) {
list = new ArrayList<T>();
}
this.list = list;
this.sheetName = title;
this.type = Type.EXPORT;
this.title = title;
createExcelField();
//使用stream将list中的数据按照fieldName进行分组
Map<String, List<T>> map = list.stream().collect(Collectors.groupingBy(t -> Convert.toStr(ReflectUtils.invokeGetter(t, fieldName))));
this.wb = new SXSSFWorkbook(500);
if (map.size() > 0) {
//map循环 设置多个不同的sheet
for (Map.Entry<String, List<T>> entry : map.entrySet()) {
this.sheet = wb.createSheet(entry.getKey());
this.styles = createStyles(wb);
createTitle();
}
}
return exportExcel();
}
/** /**
* 对list数据源将其里面的数据导入到excel表单 * 对list数据源将其里面的数据导入到excel表单
* *