Hi,
Thanks for your inquiry.
We are pleased to inform you that it is indeed possible to modify the styles of the HTML content after it has been added. To achieve this, you need to retrieve each newly added paragraph object and make the necessary style modifications.
Please refer to the following example code snippet:
- Code: Select all
Document doc = new Document();
String data ="<h1><span style=\"font-family:Times New Roman,Times,serif\">process 1</span></h1>\n" +
"<p></p>\n" +
"<p><em><u><span style=\"font-size:26pt\"><span style=\"font-family:Times New Roman,Times,serif\"><span style=\"background-color:#1abc9c\">Process2</span></span></span></u></em></p>";
Section section = doc.addSection();
// Add a table and show its border
Table table = section.addTable(true);
table.resetCells(2,2);
TableCell cell = table.getRows().get(0).getCells().get(0);
cell.addParagraph().appendHTML(data);
// Get all the paragraphs in the cell
ParagraphCollection paragraphs = cell.getParagraphs();
// Loop through each paragraph
for (int i = 0; i < paragraphs.getCount(); i++) {
Paragraph paragraph = paragraphs.get(i);
// Get the child objects of the paragraph
DocumentObjectCollection childObjects = paragraph.getChildObjects();
for (int j = 0; j < childObjects.getCount(); j++) {
// Judge the type of child object
if (childObjects.get(j).getDocumentObjectType() == DocumentObjectType.Text_Range){
TextRange textRange = (TextRange) childObjects.get(j);
// Set its font and font size ...
textRange.getCharacterFormat().setFontSize(20);
textRange.getCharacterFormat().setFontName("Calibri");
}
}
}
doc.saveToFile("result.docx");
This code allows you to access each paragraph within the cell and modify its style properties, such as font size, text color, etc., according to your specific needs.
If you have any other questions, just feel free to contact us. We are here to assist you.
Best regards,
Triste
E-iceblue support team