[引入依赖]
/**
* 写入数据导出Excel
*
* @param response
*/
@GetMapping("/writeExcel")
public void writeExcel(HttpServletResponse response) throws IOException {
ExportParams params = new ExportParams();
//生成要导出的数据
List
for (List<Object> rowList : tempDataList) {
System.out.println("这个集合的值是:" + rowList);
Map<String, Object> rowMap = new HashMap<>();
for (int i = 1; i <= rowList.size(); i++) {
rowMap.put("title" + i, rowList.get(i - 1));
}
resultList.add(rowMap);
}//列名
List<ExcelExportEntity> entityList = new ArrayList<>();
for (int i = 1; i <= tempRowList1.size(); i++) {
ExcelExportEntity entity = new ExcelExportEntity("标题" + i, "title" + i);
entityList.add(entity);
}
Workbook workbook = ExcelExportUtil.exportExcel(params, entityList, resultList);
response.addHeader("Content-Disposition", "filename=test.xlsx");
//设置类型,扩展名为.xls
response.setContentType("application/vnd.ms-excel");
workbook.write(response.getOutputStream());
}
表头的值和数据的key是需要对应的
手机扫一扫
移动阅读更方便
你可能感兴趣的文章