Cells 中的新行

Aspose.Cells - Cells 中的新线

为确保可以读取单元格中的文本,可以应用明确的换行符和文本换行。文本换行将单元格中的一行变成多行,明确的换行符正好放在你想要的地方。

要在单元格中换行文本,请使用 Style.setTextWrapped 方法。

Java

 // Add Text to the First Cell with Explicit Line Breaks

cell.get(0, 0).setValue("I am using \nthe latest version of \nAspose.Cells \nto test this functionality");

//Get Cell's Style

Style style = cell.get(0, 0).getStyle();

//Set Text Wrap property to true

style.setTextWrapped(true);

//Set Cell's Style

cell.get(0, 0).setStyle(style);

Apache POI SS - HSSF XSSF - Cells 中的新行

CellStyle.setWrapText 应适用于环绕文本。

Java

 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);

下载运行代码

下载示例代码