Hi,
i fall in this issue after creating a word table.
I set the font “Arial Narrow” on the run of the paragraphs of all the cells. I’ve noticed that the empty cells don’t have the right font, but keep the default (Calibri).
Is it a bug or is there a workaround?
here it is my code.
public class TestTableEmptyRun {
public static void main(String[] args) throws Exception {
Document doc = new Document("C:\TestTableWithEmptyRun.docx");
Table wordsTable = new Table(doc);
Row firstRow = new Row(doc);
Row secondRow = new Row(doc);
com.aspose.words.Cell cell11 = new com.aspose.words.Cell(doc);
setContent(doc, cell11, "pippo");
firstRow.appendChild(cell11);
com.aspose.words.Cell cell12 = new com.aspose.words.Cell(doc);
setContent(doc, cell12, "");
firstRow.appendChild(cell12);
com.aspose.words.Cell cell21 = new com.aspose.words.Cell(doc);
setContent(doc, cell21,"");
secondRow.appendChild(cell21);
com.aspose.words.Cell cell22 = new com.aspose.words.Cell(doc);
setContent(doc,cell22, "pluto");
secondRow.appendChild(cell22);
wordsTable.appendChild(firstRow);
wordsTable.appendChild(secondRow);
doc.getFirstSection().getBody().appendChild(wordsTable);
doc.save("C:\TestTableWithEmptyRunOutput.docx");
}
private static void setContent(Document doc, Cell wordsCell, String value) throws Exception {
Paragraph wordsParagraph = new Paragraph(doc);
setParagraphDeafultFormatting(wordsParagraph);
Run run = new Run(doc);
run.setText(value);
Font font = run.getFont();
font.setName("Arial Narraow");
font.setSize(11);
wordsParagraph.appendChild(run);
wordsCell.appendChild(wordsParagraph);
BorderCollection borders = wordsCell.getCellFormat().getBorders();
borders.getByBorderType(BorderType.BOTTOM).setLineStyle(LineStyle.SINGLE);
borders.getByBorderType(BorderType.LEFT).setLineStyle(LineStyle.SINGLE);
borders.getByBorderType(BorderType.RIGHT).setLineStyle(LineStyle.SINGLE);
borders.getByBorderType(BorderType.TOP).setLineStyle(LineStyle.SINGLE);
}
private static void setParagraphDeafultFormatting(Paragraph paragraph) throws Exception {
paragraph.getParagraphFormat().clearFormatting();
paragraph.getParagraphFormat().setLineSpacingRule(LineSpacingRule.MULTIPLE);
paragraph.getParagraphFormat().setLineSpacing(12);
paragraph.getParagraphFormat().setSpaceAfter(0);
paragraph.getParagraphFormat().setSpaceBefore(0);
}
}