当我们通过POI设置了表格的列宽的时候,如果文字过长,希望文字能够自己折行显示。
截取代码如下:
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook(); Sheet sheet = wb.createSheet(); Row row = sheet.createRow(2); Cell cell = row.createCell(2); cell.setCellValue("Use \n with word wrap on to create a new line"); CellStyle cs = wb.createCellStyle(); cs.setWrapText(true); //关键 cell.setCellStyle(cs); //单元格应用设置的style
本文介绍如何使用Java POI库设置Excel表格中的单元格文字自动换行,通过设置CellStyle的wrapText属性为true实现文字自动折行显示。

被折叠的 条评论
为什么被折叠?



