首页 > 解决方案 > Word 文档中的 NPOI 居中对齐页脚

问题描述

我有以下代码,它使用 .Net Core 的 NPOI 库将页脚插入 Word 文档。目前,页脚插入得很好,但我正在努力寻找任何关于如何对齐页脚的示例。谁能举个例子或者指出我正确的方向?

        XWPFDocument document = new XWPFDocument();

        document.Document.body.sectPr = new CT_SectPr();

        CT_Ftr footer = new CT_Ftr();
        footer.AddNewP().AddNewR().AddNewT().Value = "Copyright © " + DateTime.Now.Year;
        XWPFRelation footerRelation = XWPFRelation.FOOTER;
        XWPFFooter documentFooter = (XWPFFooter)document.CreateRelationship(footerRelation, XWPFFactory.GetInstance(), document.FooterList.Count + 1);
        documentFooter.SetHeaderFooter(footer);
        CT_HdrFtrRef footerRef = document.Document.body.sectPr.AddNewFooterReference();
        footerRef.type = ST_HdrFtr.@default;
        footerRef.id = documentFooter.GetPackageRelationship().Id;

        FileStream outStream = new FileStream("example.docx", FileMode.Create);
        document.Write(outStream);

标签: c#apache-poinpoi

解决方案


我想到了!我会把我的代码留在这里,以防其他人有同样的问题:

        CT_Ftr footer = new CT_Ftr();
        CT_P footerParagraph = footer.AddNewP();
        CT_PPr ppr = footerParagraph.AddNewPPr();
        CT_Jc align = ppr.AddNewJc();
        align.val = ST_Jc.center;

我需要在ST_Jc我的段落中添加一个。然后,我刚刚添加了一个新的运行footerParagraph,我就设置好了!


推荐阅读