easypoi应用笔记

1、导出实体类列表

只需要在实体类上增加**@Excel(name = “姓名”)**

	String fileName = "记录表";
	ExportParams exportParams = new ExportParams("记录表","记录表");
	Map map = new HashMap();
	map.put(NormalExcelConstants.DATA_LIST,实体类list);
	map.put(NormalExcelConstants.CLASS,类名.class);
	map.put(NormalExcelConstants.PARAMS,exportParams);
	map.put(NormalExcelConstants.FILE_NAME,fileName);
	PoiBaseView.render(map,request,response,NormalExcelConstants.EASYPOI_EXCEL_VIEW);

注意这里使用的是NormalExcelConstants.EASYPOI_EXCEL_VIEW,需要指定实体类class;

2、导出Map列表(无实体类的数据,动态列的数据)

public void excelExport(HttpServletRequest request, HttpServletResponse response, @RequestBody *** ***) {
	/*需要导出的原始数据*/
	List<Map<String, String>> dataList = (List<Map<String, String>>) ***.get("data");
	/*定义表头*/
	List<ExcelExportEntity> colList = new ArrayList<ExcelExportEntity>();
	/*生成动态表头*/
	for (Map.Entry<String, String> entry : dataList.get(0).entrySet()) {
	    colEntity = new ExcelExportEntity(entry.getKey(),entry.getKey());
	    colEntity.setNeedMerge(true);
	    colList.add(colEntity);
	    }
	}
	
	Map map = new HashMap();
	map.put(MapExcelConstants.ENTITY_LIST,colList);
	map.put(MapExcelConstants.MAP_LIST,dataList);
	map.put(MapExcelConstants.PARAMS,exportParams);
	map.put(MapExcelConstants.FILE_NAME,fileName);
	PoiBaseView.render(map,request,response,MapExcelConstants.EASYPOI_MAP_EXCEL_VIEW)
}

这里使用的是MapExcelConstants.EASYPOI_MAP_EXCEL_VIEW,需要生成ENTITY_LIST;

3、导出到本地文件

以上是通过http接口返回到前端,也可以导出到本地,不使用PoiBaseView.render

	Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("统计", "统计数据"), colList,dataList);
	FileOutputStream fos = new FileOutputStream("D:/分析表.xls");
	workbook.write(fos);
	fos.close();

workbook.write也可以用于http接口如:

	workbook.write(response.getOutputStream());
	workbook.close();
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值