我有一个包含页眉/页脚的模板文档,我必须插入多个文档。在每个文档之后,我需要插入一个分页符。
中有一个insertDocument()
和一个insertBreak()
。com.aspose.words.DocumentBuilder
我更喜欢使用,com.aspose.words.NodeImporter
因为它更灵活。这工作正常,但我找不到事后插入分页符的方法。
除了使用DocumentBuilder
?
我有一个包含页眉/页脚的模板文档,我必须插入多个文档。在每个文档之后,我需要插入一个分页符。
中有一个insertDocument()
和一个insertBreak()
。com.aspose.words.DocumentBuilder
我更喜欢使用,com.aspose.words.NodeImporter
因为它更灵活。这工作正常,但我找不到事后插入分页符的方法。
除了使用DocumentBuilder
?
请尝试使用以下代码:
Document doc = new Document(filePath);
NodeCollection col = doc.GetChildNodes(NodeType.Paragraph, true);
Paragraph para = (Paragraph)col[col.Count - 2];
Table tab = (Table)para.GetAncestor(NodeType.Table);
if (tab != null)
{
// it means last para is inside table
Paragraph newPara = new Paragraph(doc);
newPara.Runs.Add(new Run(doc, ControlChar.PageBreak));
newPara.ParagraphBreakFont.Size = 1;
tab.ParentNode.InsertAfter(newPara, tab);
}else
{
// normal case
}
doc.Save(MyDir + @"16.7.0.docx");
我与 Aspose 一起担任开发人员宣传员。
请使用以下方法:
doc.FirstSection.Body.FirstParagraph.Runs.Add(new Run(doc, ControlChar.PageBreak));
我与 Aspose 一起担任开发人员宣传员。