标签:lis 设置 ESS void list集合 control 导出 ons 生活
1、添加依赖
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
2、service层
public void download(HttpServletResponse response) throws ServiceException {
//表格标题,就是模型的属性名
String[] titles = {"月份", "姓名", "电话", "身份证", "银行卡号", "职务工资", "级别工资", "一次性补发工资", "基本工资小计",
"工作性补贴", "生活性补贴", "工改保留津贴", "特殊岗位津补贴", "津补贴小计", "发独子费", "应发工资", "代扣公积金",
"代扣医疗费", "代扣养老", "代扣职业年金", "补缴1-5月公积金", "实发工资", "代扣个人所得税", "代扣缴公积金", "税后工资"};
//将list集合数据变成String类型二维的数组,行数+列数
String[] datas = new String[titles.length];
//表格sheet名
String sheetName = "工资表";
//调用common下的Excel导出方法,导出Excel
HSSFWorkbook workbook = downloadExcel(sheetName, titles);
try {
//文件名,需要编码成ISO8859-1
String fileName = new String("员工信息表.xls".getBytes("UTF-8"), "ISO8859-1");
//设置响应头,返回前端下载文件
response.setHeader("content-Disposition", "attachment;filename=" + fileName);
workbook.write(response.getOutputStream());
} catch (Exception e) {
throw new ServiceException(Codes.SYSTEM_EXCEPTION, "请联系管理员");
}
}
3、controller
@GetMapping("/download")
@SysAuthentication
public Response download(HttpServletResponse response) throws ServiceException {
wagesInfoService.download(response);
return success();
}
标签:lis 设置 ESS void list集合 control 导出 ons 生活
原文地址:https://www.cnblogs.com/summerOnlyOne/p/12791047.html