easyexcel样式设置
//内容样式策略 WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); //垂直居中,水平居中 contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); contentWriteCellStyle.setBorderLeft(BorderStyle.THIN); contentWriteCellStyle.setBorderTop(BorderStyle.THIN); contentWriteCellStyle.setBorderRight(BorderStyle.THIN); contentWriteCellStyle.setBorderBottom(BorderStyle.THIN); //设置 自动换行 // contentWriteCellStyle.setWrapped(true); // 字体策略 WriteFont contentWriteFont = new WriteFont(); // 字体大小 contentWriteFont.setFontHeightInPoints((short) 12); contentWriteFont.setFontName("宋体"); contentWriteCellStyle.setWriteFont(contentWriteFont); //头策略使用默认 设置字体大小 WriteCellStyle headWriteCellStyle = new WriteCellStyle(); WriteFont headWriteFont = new WriteFont(); headWriteFont.setFontHeightInPoints((short) 12); headWriteFont.setFontName("宋体"); headWriteCellStyle.setWriteFont(headWriteFont); headWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.index); // String fileName="数据汇总表"+getNowDate(); String fileName= LocalDateTime.now().toString(); //将文件名称转码再使用 fileName = URLEncoder.encode(fileName, "UTF-8"); // response.setHeader("Content-Disposition", "attachment;filename*= UTF-8''"+ URLEncoder.encode(fileName,"UTF-8")); response.setHeader("Content-Disposition", "attachment;filename=" + fileName+".xlsx") ; OutputStream out=response.getOutputStream(); ExcelWriter excelWriter = EasyExcel.write(out).registerWriteHandler(new CustomCellWriteHandler()). registerWriteHandler(new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle)) .registerWriteHandler(new SimpleRowHeightStyleStrategy((short)22,(short)22)) // .registerWriteHandler(new CustomCellWriteHandler()) .build();
//导入多个sheet
excelWriter = EasyExcel.write(response.getOutputStream()).registerWriteHandler(new CustomCellWriteHandler()).build();
//创建一个sheet
WriteSheet writeSheet = EasyExcel.writerSheet(0, "模板1").registerWriteHandler(horizontalCellStyleStrategy).build();
excelWriter.write(list, writeSheet);
//创建一个新的sheet
writeSheet = EasyExcel.writerSheet(1, "模板2").registerWriteHandler(horizontalCellStyleStrategy).build();
excelWriter.write(list, writeSheet);