Hi Adam,
In our app, we have code to check the headings in a particular word document. But for some type of headings (eg: Heading 1_0) it’s not working as expected. For example, in the attached document we have several headings, but code not detecting those and giving zero headings. Pls guide us.
PFB the piece of code we have written and PFA the document we are facing issue.
final NodeCollection paragraphColl = doc.getChildNodes(NodeType.PARAGRAPH, true);
int maxhdr = 1;
int prevStyleId = 0;
for (Iterator iterator = paragraphColl.iterator(); iterator.hasNext();) {
final Paragraph paragraph = (Paragraph)iterator.next();
String nodeStyle = paragraph.getParagraphFormat().getStyle().getName();
String tocText = paragraph.toTxt().trim();
if (tocText == null || tocText.equals("")) { continue; }
int styleId = paragraph.getParagraphFormat().getStyleIdentifier();
if (paragraph.getParagraphFormat().isHeading()) { // looks like not detecting here
TemplateSection ts = null;
if (styleId - prevStyleId > 1) {
for (int i = prevStyleId + 1; i < styleId; i++) {
ts = new TemplateSection();
ts.setStyleId(i);
ts.setDummy(true);
headingSections.add(ts);
}
}
ts = new TemplateSection();
ts.setNodeStyle(nodeStyle);
ts.setStyleId(styleId);
ts.setSectionName(tocText);
ts.setDummy(false);
headingSections.add(ts);
if (styleId > maxhdr) maxhdr = styleId;
prevStyleId = styleId;
}
}
This code works fine for Heading 1 type. Tested and verified.
This message was posted using Email2Forum by aske012. (private)