easypoi自定义字段导出到表格
1.添加依赖
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>3.2.0</version>
</dependency>
2.编写类
public static void test() {
try {
List beanList =new ArrayList();
beanList.add(new ExcelExportEntity("学生姓名", "name"));
beanList.add(new ExcelExportEntity("学生性别", "sex"));
beanList.add(new ExcelExportEntity("进校日期", "registrationDate"));
beanList.add(new ExcelExportEntity("出生日期", "birthday"));
List> list =new ArrayList>();
for(int i=0;i<5;i++){
Map map =new HashMap<>();
map.put("name",i+"aa");
map.put("sex",i+"bb");
map.put("registrationDate",i+"cc");
map.put("birthday",i+"dd");
list.add(map);
}
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("测试", "测试"), beanList,list);
FileOutputStream fos =new FileOutputStream("D:/excel/ExcelExportForMap.tt.xls");
workbook.write(fos);
fos.close();
}catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Test.test();
}