-
Notifications
You must be signed in to change notification settings - Fork 325
Dynamic export
清沐 edited this page Feb 18, 2020
·
2 revisions
There are three types of dynamic export:
- Dynamically specify the title and field order;
- Field grouping;
- Map export;
// title
List<String> titles = new ArrayList<>();
titles.add("姓名");
titles.add("年龄");
// field display order
List<String> order = new ArrayList<>();
order.add("name");
order.add("age");
// display data
List<TestDO> dataList = this.getData();
Workbook workbook = DefaultExcelBuilder.of(TestDO.class)
.sheetName("default example")
.titles(titles)
.fieldDisplayOrder(order)
.build(dataList);
private List<TestDO> getData(){
TestDO testDO = new TestDO();
testDO.setName("张三");
TestDO testDO1 = new TestDO();
testDO1.setName("李四");
TestDO testDO2 = new TestDO();
testDO2.setName("王五");
testDO2.setAge(15);
TestDO testDO3 = new TestDO();
testDO3.setName("陈六");
testDO3.setAge(25);
List<TestDO> dataList = new ArrayList<>();
dataList.add(testDO);
dataList.add(testDO1);
dataList.add(testDO2);
dataList.add(testDO3);
return dataList;
}
This method is based on the groups attribute of annotation @ExcelColumn
@ExcelColumn(title="姓名",groups={People.class})
String name;
@ExcelColumn(title="年龄")
String age;
DefaultExcelBuilder.of(ArtCrowd.class).build(People.class);
The above example will only export the "name" field
Map<String, String> headerMap = new HashMap<>();
headerMap.put("a", "测试A");
headerMap.put("b", "测试B");
List<Map> dataMapList = new ArrayList<>();
Map<String, Object> v1 = new HashMap<>();
v1.put("a", "数据a1");
v1.put("b", 3);
Map<String, Object> v2 = new HashMap<>();
v2.put("a", "数据a2");
v2.put("b", 5);
dataMapList.add(v1);
dataMapList.add(v2);
List<String> titles = new ArrayList(headerMap.values());
List<String> orders = new ArrayList(headerMap.keySet());
Workbook workbook = DefaultExcelBuilder.of(Map.class)
.sheetName("sheet1")
.titles(titles)
.widths(10,20)
.fieldDisplayOrder(orders)
.build(dataMapList);
FileExportUtil.export(workbook, new File("/tmp/zz.xlsx"));
-
Overview
概述 -
FAQ
常见问题 -
Dependency adding
依赖添加 -
Excel/Csv import
Excel/Csv导入 - 一对多导入
-
Excel default export
默认导出 -
Excel streaming export
流式导出 -
Dynamic export
动态导出 -
Excel template build
模板构建 -
CSV export
csv导出 -
Multiple sheet import
多sheet导入 -
Multiple sheet export
多sheet导出 - 聚合列&聚合导出
-
Custom style
自定义样式 -
Multilevel header
多级表头 -
Wrap within cell
单元格内换行 -
Image export
图片导出 -
Image import
图片导入 -
Hyperlink
链接 - 读取链接
-
Template row height setting
模板行高度设置 -
Drop-down-list
下拉列表 -
Custom convert
写入自定义转化 -
Formula usage
公式使用 -
Template cell setting
单元格设置 -
Header freeze
区域冻结 - 提示
-
Style support
样式支持 - 添加水印
- 按列读取
- 单元格斜线绘制
- 设置批注
- 版本日志