HSSFWorkbook强制换行

设置单元格格式为允许换行

 // 设置单元格格式为允许换行
HSSFCellStyle style = wb.createCellStyle();
style.setWrapText(true);

增加单元格高度,来适应强制换行之后的单元格高度

//增加单元格的高度 以能够容纳3行字

row.setHeightInPoints(3*sheet.getDefaultRowHeightInPoints());

 

对单元格内的内容进行强制换行

String recIndName = "hello,change to the next line";
// /r/n的意思是 换行 + 空格 recIndName
= recIndName.replace(",","\r\n"); cell = row.createCell(col); cell.setCellStyle(style); cell.setCellValue(new HSSFRichTextString(recIndName));

 

posted @ 2021-04-14 15:13  浅笑19  阅读(669)  评论(0编辑  收藏  举报