Word 文档中的 NPOI 居中对齐页脚

NPOI Center-Align Footer in Word Document

我有以下代码,它使用 .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);

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

        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 就设置好了!