简单的poi导出例子

@RequestMapping("/sms/salary/exportSalaryAnalyse.do")//前台请求的方法
public void exportSalaryAnalyse(HttpServletRequest req, HttpServletResponse response)throws Exception {

List<map<String,Object>> list = salaryService.exportWage();//根据条件查询出符合条件的信息装入容器


Map<String, List<Map<String, Object>>> excelMap = new HashMap<String, List<Map<String, Object>>>();
// sheet
List<Map<String, Object>> sheetList = new ArrayList<Map<String, Object>>();
// row 行数
for (int j = 0; j < list.size(); j++) {

Map<String, Object> hashMap = new HashMap<String, Object>();


map<String,Object> vo = list.get(j);


// cell 每行中每列的值 注意列字不能少

hashMap.put("列" + 0, ActionHelper.toStr(j + 1)); //序号


hashMap.put("列" + 1, vo.getkey("A")); 

hashMap.put("列" + 2, vo.getkey("B"));

hashMap.put("列" + 3, vo.getkey("C"));

hashMap.put("列" + 4, vo.getkey("D"));



sheetList.add(hashMap);
}
excelMap.put("收入分析", sheetList);
// 正常表头  注意列字不能少
LinkedHashMap<String, String> head = new LinkedHashMap<String, String>();
head.put("列" + 0, "序号");
head.put("列" + 1, "人员代码");
head.put("列" + 2, "人员姓名");
head.put("列" + 3, "机构名称");
head.put("列" + 4, "计算月份");




// 设置每个sheet页的表头
List<LinkedHashMap<String, String>> sheetHead = new ArrayList<LinkedHashMap<String, String>>();
sheetHead.add(head);
// 设置多sheet页
Map<String, List<LinkedHashMap<String, String>>> map = new HashMap<String, List<LinkedHashMap<String, String>>>();
map.put("收入分析", sheetHead); //对应上面excelMap put的招募情况报表


ExcelWrite write = new ExcelWrite();
//设置response 这样就可以前台弹出框进行下载了
response.setContentType("application/msexcel");
response.setHeader("Content-disposition", "attachment; filename="
+ DateHelper.getSysStr("yyyyMMddHHmmss") + "export.xls");
write.setResponse(response);
write.setSheetHead(map);
write.setMergeCell(true);
//write.addNotLockArea("测试1", "A3:F8");
// 设置数据,key需要跟sheet页的key相同,值为需要写的数据
write.writeExcel(excelMap);
return null;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值