首页 新闻 搜索 专区 学院

c# Aspose.word 如何自定义页眉上的页码

0
悬赏园豆:5 [已解决问题] 解决于 2018-04-21 17:12

c# Aspose.word 如何自定义页眉上的页码

Mr.Myr的主页 Mr.Myr | 初学一级 | 园豆:3
提问于:2018-04-11 19:26
< >
分享
最佳答案
1

参考 How to insert custom page number in Aspose.Words

String src = dataDir + "Page numbers.docx";
String dst = dataDir + "Page numbers_out.docx";

// Create a new document or load from disk
Aspose.Words.Document doc = new Aspose.Words.Document(src);
// Create a document builder
Aspose.Words.DocumentBuilder builder = new DocumentBuilder(doc);
// Go to the primary footer
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
// Add fields for current page number
builder.InsertField("PAGE", "");
// Add any custom text
builder.Write(" / ");
// Add field for total page numbers in document
builder.InsertField("NUMPAGES", "");

// Import new document
Aspose.Words.Document newDoc = new Aspose.Words.Document(dataDir + "new.docx");
// Link the header/footer of first section to previous document
newDoc.FirstSection.HeadersFooters.LinkToPrevious(true);
doc.AppendDocument(newDoc, ImportFormatMode.UseDestinationStyles);
// Save the document
doc.Save(dst);
收获园豆:5
dudu | 高人七级 |园豆:38304 | 2018-04-11 20:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册