Hi i am trying to fill a Table and some cells contain text with new line \n, but this new line is not shown on the Table. We write more complicated code, but even this simple example doesn’t add a new line.
@Test
public void testTableCellsWithLine() throws Exception {
Document document = new Document();
DocumentBuilder builder = new DocumentBuilder(document);
builder.startTable();
builder.insertCell();
builder.endRow();
builder.endTable();
Table table = (Table) document.getChild(NodeType.TABLE, 0, true);
Cell cell = table.getFirstRow().getFirstCell();
cell.getCellFormat().setFitText(false);
// If true, wrap text for the cell.
cell.getCellFormat().setWrapText(true);
Paragraph paragraph = new Paragraph(document);
Run run = new Run(document, "i want a \n new line");
paragraph.appendChild(run);
cell.appendChild(paragraph);
document.save("C:\\Documents\\BDC_General\\TableWithLine.docx");
}
The same problem applies with that kind of code:
cell.getParagraphs()
.get(0)
.getRuns()
.get(0)
.setText("I want \n a new line");
I attach the word document to see that there is no new line there. TableWithLine.docx (17.4 KB)
Thank you,
Eleftheria