Hello, I want to update a Document with different styles based on some values.
If the paragraph just contains for example “A”, it should have a heading 1, but the next paragraphs “Abstract”, “Aspose” etc should have a body text style.
At the moment all paragraphs seem to remain as the default body text style…
I’ve also tried updating the style of the run, which resulted in all paragraphs being heading 1.
This is the code I’m currently using, could you let me know what’s causing errors?
public static void Insert(List listPara, String docName) throws Exception {
Document doc = new Document();
Paragraph paragraph = doc.getFirstSection().getBody().getFirstParagraph();
for (String paragraphText : listPara) {
if (paragraphText.length() == 2){
Run run = new Run(doc, paragraphText);
paragraph.appendChild(run);
paragraph.getParagraphFormat().setStyleIdentifier(1); // HEADING 1 Style Identifier
doc.updateFields();
doc.save(docName);
} else {
Run run = new Run(doc, paragraphText);
paragraph.appendChild(run);
paragraph.getParagraphFormat().setStyleIdentifier(66); // Body Text Style Identifier
doc.updateFields();
doc.save(docName);
}}