添加 header 后,我无法在 aspose.word 中插入分节符

i cant insert section break in aspose.word after add header

在 aspose.word 中插入 header 之后我想插入 BreackNewPage 但 在 .Net 的 aspose.word 中插入分节符时出现异常 我的代码在这里:

builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
        Shape shape = builder.InsertImage(dataDir);
        shape.Height = builder.PageSetup.PageHeight - 200;
        shape.Width = builder.PageSetup.PageWidth - 50;        
        shape.WrapType = WrapType.None;
        shape.BehindText = true;
        shape.RelativeHorizontalPositionRelativeHorizontalPosition.Page;
        shape.RelativeVerticalPosition = RelativeVerticalPosition.Page;
        shape.VerticalAlignment = VerticalAlignment.Center;
        builder.InsertBreak(BreakType.SectionBreakNewPage);

您的光标需要位于 "main Story" 内才能插入请求的中断。请看以下代码:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
Shape shape = builder.InsertImage(MyDir + @"aspose.words.jpg");
shape.Height = builder.PageSetup.PageHeight - 200;
shape.Width = builder.PageSetup.PageWidth - 50;
shape.WrapType = WrapType.None;
shape.BehindText = true;            
shape.RelativeVerticalPosition = RelativeVerticalPosition.Page;
shape.VerticalAlignment = VerticalAlignment.Center;
builder.MoveToDocumentEnd();
builder.InsertBreak(BreakType.SectionBreakNewPage);
doc.Save(MyDir + @"17.11.docx");

我在 Aspose 工作,担任开发人员推广员。

您可以使用 aspose.word 提供的简单函数作为

Document doc = new Document();
DocumentBuilder documentBuilder= new DocumentBuilder(doc);
documentBuilder.MoveToDocumentEnd(); //moving cursor to end of page.
documentBuilder.InsertBreak(BreakType.SectionBreakNewPage); // creating new page.
documentBuilder.PageSetup.ClearFormatting(); //clear formatting.