easyExcel设置自动换行

 1 //内容样式策略
 2         WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
 3         //垂直居中,水平居中
 4         contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
 5         contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
 6         contentWriteCellStyle.setBorderLeft(BorderStyle.THIN);
 7         contentWriteCellStyle.setBorderTop(BorderStyle.THIN);
 8         contentWriteCellStyle.setBorderRight(BorderStyle.THIN);
 9         contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);
10 
11         //设置 自动换行
12 //        contentWriteCellStyle.setWrapped(true);
13         // 字体策略
14         WriteFont contentWriteFont = new WriteFont();
15         // 字体大小
16         contentWriteFont.setFontHeightInPoints((short) 12);
17         contentWriteFont.setFontName("宋体");
18         contentWriteCellStyle.setWriteFont(contentWriteFont);
19 
20         //头策略使用默认 设置字体大小
21         WriteCellStyle headWriteCellStyle = new WriteCellStyle();
22         WriteFont headWriteFont = new WriteFont();
23         headWriteFont.setFontHeightInPoints((short) 12);
24         headWriteFont.setFontName("宋体");
25         headWriteCellStyle.setWriteFont(headWriteFont);
26         headWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.index);
27 
28 //        String fileName="数据汇总表"+getNowDate();
29         String fileName= LocalDateTime.now().toString();
30         //将文件名称转码再使用
31          fileName = URLEncoder.encode(fileName, "UTF-8");
32 //        response.setHeader("Content-Disposition", "attachment;filename*= UTF-8''"+ URLEncoder.encode(fileName,"UTF-8"));
33         response.setHeader("Content-Disposition", "attachment;filename=" + fileName+".xlsx") ;
34         OutputStream out=response.getOutputStream();
35         ExcelWriter excelWriter  = EasyExcel.write(out).registerWriteHandler(new CustomCellWriteHandler()).
36                 registerWriteHandler(new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle))
37                 .registerWriteHandler(new SimpleRowHeightStyleStrategy((short)22,(short)22))
38 //                .registerWriteHandler(new CustomCellWriteHandler())
39                 .build();
40 //导入多个sheetexcelWriter  = EasyExcel.write(response.getOutputStream()).registerWriteHandler(new CustomCellWriteHandler()).build();//创建一个sheetWriteSheet writeSheet = EasyExcel.writerSheet(0, "模板1").registerWriteHandler(horizontalCellStyleStrategy).build();excelWriter.write(list, writeSheet);//创建一个新的sheetwriteSheet = EasyExcel.writerSheet(1, "模板2").registerWriteHandler(horizontalCellStyleStrategy).build();excelWriter.write(list, writeSheet);

 

posted @ 2023-08-01 16:43  charmtool  阅读(1727)  评论(0编辑  收藏  举报