你好,我的输入文档:
项目进度计划.docx (21.0 KB)
代码:
Document document = new Document("D:\\xxx\\项目进度计划.docx");
NodeCollection<Paragraph> childNodes = document.getChildNodes(NodeType.PARAGRAPH, true);
document.startTrackRevisions("DF ");
for (Paragraph childNode : childNodes) {
if (childNode.getParagraphFormat().isHeading()) {
Paragraph paragraph = new Paragraph(document);
paragraph.getParagraphFormat().setStyleName("Heading 1");
paragraph.appendChild(new Run(document, "新增章节"));
childNode.getParentNode().insertBefore(paragraph, childNode);
break;
}
}
document.updateListLabels();
NodeCollection<Paragraph> paragraphs = document.getChildNodes(NodeType.PARAGRAPH, true);
for (Paragraph paragraph : paragraphs) {
String text = paragraph.getText();
if (text.contains("新增章节")) {
String labelString = paragraph.getListLabel().getLabelString();
System.out.println(labelString);
}
}
labelString 值为空,按理说值应该为 1 才对,请问是为什么呢?