如何插入换行符作为单元格的数据?
问题内容:
我使用Apache POI 3.16创建一个Excel文件。我想将特定单元格内的数据设置为换行符:
rowConsommationEtRealisation.createCell(0).setCellValue("Consommation (crédits)\r\nRéalisation (produits)");
当我打开文件时,单元格值没有换行符!那么如何创建换行符呢?
问题答案:
试试这个:这里
Row row = sheet.createRow(2);
Cell cell = row.createCell(2);
cell.setCellValue("Use \n with word wrap on to create a new line");
//to enable newlines you need set a cell styles with wrap=true
CellStyle cs = wb.createCellStyle();
cs.setWrapText(true);
cell.setCellStyle(cs);