【发布时间】:2023-04-02 19:30:01
【问题描述】:
我正在使用 NPOI 2.5.2 生成一个 docx 文件,但我坚持使用首页的页眉/页脚。 我想要一个第一页自定义页脚并从第二页开始编号页面。
这是我的第一页页脚代码:
// First page
doc.Document.body.sectPr = new CT_SectPr();
var footer = new CT_Ftr();
var footerParagraph = footer.AddNewP();
footerParagraph.AddNewR().AddNewT().Value = $"FIRST PAGE CUSTOM FOOTER";
var footerPar = new XWPFParagraph(footerParagraph, doc);
var parsFooter = new XWPFParagraph[1];
parsFooter[0] = footerPar;
var headerFooterPolicy = doc.GetHeaderFooterPolicy();
if (headerFooterPolicy == null)
headerFooterPolicy = doc.CreateHeaderFooterPolicy();
headerFooterPolicy.CreateFooter(XWPFHeaderFooterPolicy.FIRST, parsFooter);
这是我的带有页码的默认页脚的代码:
// Other pages
footerParagraph = footer.AddNewP();
footerParagraph.AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.begin;
footerParagraph.AddNewR().AddNewInstrText().Value = " PAGE ";
footerParagraph.AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.separate;
footerParagraph.AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.end;
footerPar = new XWPFParagraph(footerParagraph, doc);
parsFooter = new XWPFParagraph[1];
parsFooter[0] = footerPar;
headerFooterPolicy.CreateFooter(XWPFHeaderFooterPolicy.DEFAULT, parsFooter);
使用上面的代码,我看不到第一页的自定义页脚,而是每页中的页码。我做错了什么?
我找到了this similar question,但在 NPOI 中找不到addNewTitlePg 方法。
是否有任何适当的文档,其中包含有关 NPOI 的示例?
【问题讨论】:
标签: c# apache-poi footer docx npoi