2017-11-22 2 views
-1

を追加aspose.wordでセクション区切りを挿入カントが、ネット ためaspose.wordで挿入セクション区切りは、私のコードはここにあるときに 例外が発生しました:私は後に、私はBreackNewPage 挿入したい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); 
+0

'builder.MoveToHeaderFooter'を指定すると、ヘッダにセクション区切りを追加しようとしていることが気に入らないと思いますか? – mjwills

+0

System.InvalidOperationException –

+0

true ...だから@mjwills –

答えて

1

要求された区切りを挿入できるようにするには、カーソルが「メインストーリー」内にある必要があります。次のコードを参照してください:

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を使用しています。

関連する問題