here are my two TOC Field that generated through codes.
but now I want to move of of it to the following section(i mean a section created and attached the the current one), I have tried that, but that doesn’t work… how should i do it?
@Madecho The simplest solution will be removing TOC field from one section and inserting the TOC field with the same field code into another section.
@alexey.noskov hello alexey.
{
ParagraphCollection paragraphCollection = section.getBody().getParagraphs();
if (formattingProcessShareVar.getShapeCount() > 0)
{
Paragraph paragraph = new Paragraph(section.getDocument());
paragraphCollection.add(paragraph);
paragraph.appendField("TOC \\h \\z \\c \"图\"");
}
Paragraph pageBreakParagraph = new Paragraph(section.getDocument());
pageBreakParagraph.appendChild(new Run(section.getDocument(), ControlChar.PAGE_BREAK));
paragraphCollection.add(pageBreakParagraph);
Paragraph newPageContent = new Paragraph(section.getDocument());
Run run = new Run(section.getDocument(), "这是新页面上的内容。");
newPageContent.appendChild(run);
newPageContent.appendField("TOC \\h \\z \\c \"表\"");
paragraphCollection.add(newPageContent);
}
here’s my code, but at newPageContent.appendField("TOC \\h \\z \\c \"表\"");
, comes out a exception said 'Cannot invoke com.aspose.words.CompositeNode.insertAfter(com.aspose.words.Node, com.aspose.words.Node)
because the return value of com.aspose.words.Node.getParentNode()
is null
, why?
the run content can be added at the next page if newPageContent.appendField("TOC \\h \\z \\c \"表\"");
was not added, so i thought i can use newPageContent.appendField("TOC \\h \\z \\c \"表\"");
to achieve my goal
@Madecho To use Paragraph.appendField
method, you should first add the paragraph into the document. Please modify your code like this:
Paragraph newPageContent = new Paragraph(section.getDocument());
paragraphCollection.add(newPageContent); // Add document into the DOM
Run run = new Run(section.getDocument(), "这是新页面上的内容。");
newPageContent.appendChild(run);
newPageContent.appendField("TOC \\h \\z \\c \"表\"");