- Code: Select all
List<Object> lstTexts = getAllElementFromObject(wordTemplate.getMainDocumentPart(), Text.class);
for (Object text : lstTexts) {
Text textElement = (Text) text;
if (textElement.getValue().equalsIgnoreCase("p" + intPageNumber + "l1")) {
textElement.setValue("");
for (Iterator iterator = lstOEQB.iterator(); iterator.hasNext();) {
OpenEndedQuestionBean oeqb = (OpenEndedQuestionBean) iterator.next();
wordTemplate.getMainDocumentPart().addObject(createNumberedParagraph(1, 0, "List", wmlObjectFactory));
}
}
}
List is generated here:
- Code: Select all
private P createNumberedParagraph(long numId, long ilvl, String paragraphText, ObjectFactory wmlObjectFactory) {
P p = wmlObjectFactory.createP();
Text t = wmlObjectFactory.createText();
t.setValue(paragraphText);
R run = wmlObjectFactory.createR();
run.getRunContent().add(t);
p.getParagraphContent().add(run);
PPr ppr = wmlObjectFactory.createPPr();
p.setPPr(ppr);
// Create and add <w:numPr>
PPrBase.NumPr numPr = wmlObjectFactory.createPPrBaseNumPr();
ppr.setNumPr(numPr);
// The <w:ilvl> element
PPrBase.NumPr.Ilvl ilvlElement = wmlObjectFactory.createPPrBaseNumPrIlvl();
numPr.setIlvl(ilvlElement);
ilvlElement.setVal(BigInteger.valueOf(ilvl));
// The <w:numId> element
PPrBase.NumPr.NumId numIdElement = wmlObjectFactory.createPPrBaseNumPrNumId();
numPr.setNumId(numIdElement);
numIdElement.setVal(BigInteger.valueOf(numId));
return p;
}