把Map对象导入Excel文件

把Map对象导入Excel文件

摘要

把Map对象导入Excel文件

Excel导入导出

excel导入导出算是比较常用的功能,这里找一个开源项目,看看效果.
https://www.oschina.net/p/easypoi_excel

POM

<dependency>
        <groupId>org.jeecg</groupId>
        <artifactId>easypoi-base</artifactId>
        <version>2.3.1</version>
</dependency>

实例

参考 https://www.oschina.net/p/easypoi_excel

把Map对象导入Excel文件

List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();
entity.add(new ExcelExportEntity("姓名", "name"));
entity.add(new ExcelExportEntity("性别", "sex"));

List<Map<String, String>> list = new ArrayList<Map<String, String>>();
Map<String, String> map;
for (int i = 0; i < 10; i++) {
map = new HashMap<String, String>();
map.put("name", "1" + i);
map.put("sex", "2" + i);
list.add(map);
}

Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), entity, list);
workbook.write(new FileOutputStream(new File("D://2.xls")));

输出文档