Here is the downloaded word file which is showing the new lines as boxes, refer the cell contents of columns 1 , 2.
Here is the actual word file , which was uploaded.
I’m generating tables by below
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.TOP);
builder.getCellFormat().setWrapText(true);
com.aspose.words.Cell dataCell = builder.insertCell();
Run run = new Run(document, data.getText());
dataCell.getFirstParagraph().appendChild(run);
@praveentermgrid You should use DocumentBuilder.write
method in your code:
Document document = new Document("C:\\Temp\\in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.TOP);
builder.getCellFormat().setWrapText(true);
com.aspose.words.Cell dataCell = builder.insertCell();
builder.write(data.getText());
Most likely data.getText()
contains paragraph breaks, which are improperly interpreted when they occur in Run. When you use DocumentBuilder.write
the paragraph breaks are inserted as actual paragraph breaks.
@alexey.noskov I’m using run because , i need to set styling properties for example
run.getFont().setItalic(Objects.equals(data.getStyle().get("fontStyle"), "italic"));
run.getFont().setBold(Objects.equals(data.getStyle().get("fontWeight"), "bold"));
run.getFont().setColor(Color.decode(data.getStyle().get("color")))
that is why I’m using runs. How do I set these run properties If I don’t use run?
@praveentermgrid You can use the following code:
builder.getFont().setItalic(Objects.equals(data.getStyle().get("fontStyle"), "italic"));
builder.getFont().setBold(Objects.equals(data.getStyle().get("fontWeight"), "bold"));
builder.getFont().setColor(Color.decode(data.getStyle().get("color")));
builder.write(data.getText());
1 Like