update ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java.
新增一个 对list数据源将其里面的数据根据字段分组导入到excel表单的方法
This commit is contained in:
parent
035c326071
commit
323fbcbaae
|
|
@ -429,6 +429,37 @@ public class ExcelUtil<T>
|
|||
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表单
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue