Hi Support Team,
DocTable.zip (42.8 KB)
I am sitting on a small challenge which I can’t get fixed.
Problem is the following:
I am reading a word file, getting the table and add rows to it which works almost very good already.
But in the last column I am adding a Ref Field which should point to a bookmark.
Works also very good already. But the Font layout (size and bold) is taken from the Bookmark itself.
I want to change the font and size in the table now but it seems like it does not work.
MS Word is also taking the font from the bookmark, but i can still change it afterwords.
Any ideas how to solve it?
Thats the source:
Document doc = new Document("G:\\Test\\Docx\\DocTable\\Table.docx");
Table table = doc.getFirstSection().getBody().getTables().get(0);
Row newRow = (Row) table.getLastRow().deepClone(true);
for (int j = 0; j < newRow.getCells().getCount(); j++) {
for (Cell cell : newRow.getCells()) {
cell.removeAllChildren();
cell.getCellFormat().getShading().setBackgroundPatternColor(Color.WHITE);
cell.appendChild(new Paragraph(doc));
switch (j) {
case 0:
cell.getFirstParagraph().appendChild(new Run(doc, "Column 1"));
break;
case 1:
cell.getFirstParagraph().appendChild(new Run(doc, "Column 2"));
break;
case 2:
Run run = new Run(doc, "Column 3");
Font f = run.getFont();
f.setColor(new Color(114, 21, 208));
cell.getFirstParagraph().appendChild(run);
break;
case 3:
System.out.println("###" + cell.getFirstParagraph().getParagraphBreakFont().getSize());
cell.getFirstParagraph().getParagraphBreakFont().setSize(10);
cell.getFirstParagraph().insertField("Ref Book \\h ", null, true);
break;
}
j++;
}
}
table.appendChild(newRow);
doc.save("G:\\Test\\Docx\\DocTable\\docx2.docx");