@GetMapping("/excel")
@RequiresPermissions("sysUserDetail:excel")
@ApiOperation(httpMethod = "GET", value = "导出")
public void excel(HttpServletResponse response) {
try {
List<SysUserDetail> sysUserDetailList = sysUserDetailService.queryListAll();
HSSFWorkbook wb = new HSSFWorkbook();
Date date = new Date();
HSSFSheet sheet = wb.createSheet("人事档案1"+date.getTime()); //创建sheet
HSSFRow row = null;
row = sheet.createRow(0);
row.setHeight((short) (30 * 20));
row.createCell(0).setCellValue("人事档案");
CellRangeAddress rowRegion = new CellRangeAddress(0, 0, 0, 2);
sheet.addMergedRegion(rowRegion);
row = sheet.createRow(1);
row.setHeight((short) (22.50 * 20));//设置行高
row.createCell(0).setCellValue("序号");//为第一个单元格设值
row.createCell(1).setCellValue("是否在职");//为第二个单元格设值
row.createCell(2).setCellValue("昵称");//为第三个单元格设值
for (int i = 0; i < sysUserDetailList.size(); i++) {
row = sheet.createRow(i + 2);
SysUserDetail sysUserDetail = sysUserDetailList.get(i);
row.createCell(0).setCellValue(sysUserDetail.getId());
row.createCell(1).setCellValue(TenureStatusEnum.queryName(sysUserDetail.getTenureStatus()));
row.createCell(2).setCellValue(sysUserDetail.getNickname());
}
sheet.setDefaultRowHeight((short) (16.5 * 20));
//列宽自适应
for (int i = 0; i <= 3; i++) {
sheet.autoSizeColumn(i);
}
response.setContentType("application/vnd.ms-excel;charset=utf-8");
OutputStream os = response.getOutputStream();
response.setHeader("Content-disposition", "attachment;filename=人事档案3"+date+".xls");//默认Excel名称
wb.write(os);
os.flush();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}