首先,本来没准备写的,但是在网上找了很多文本换行导出没效果,终于在多次尝试下有用了,难以表达激动的心情。
1. 首先创建数据行(根据自己项目哦)
row = sheet.createRow(4);
2.合并标题
// 参数:起始行号,终止行号, 起始列号,终止列号
sheet.addMergedRegion( new CellRangeAddress(0,0, 0, 16));
3.设置行高(根据项目实际)
row.setHeightInPoints(135);
4.创建格式
HSSFCellStyle style = wb.createCellStyle();
// 设置自动换行
style .setWrapText(true);
5.文本内容
换行用"\r\n",和文本分开
String str = "滴滴滴滴" +"\r\n"+"嘀嘀嘀嘀嘀嘀";
6.最后,
HSSFCell cell= null;
cell= row.createCell(0);
cell.setCellStyle(style);
cell.setCellValue(new HSSFRichTextString(str));
可以了,导出以后就可以看见换行了;如没成功,那么请尝试其他方法。