1

我试图在添加每个 altchunk 后添加不同的页脚。但是我的代码更改了所有页脚,最后一页有两个页脚。在添加具有不同文本的新页脚之前,我添加了一个分节符。(C# 和 OpenXml)

    public static void AppendFooter(string sFtText, string sFile)
    {
        using (WordprocessingDocument wdDoc = WordprocessingDocument.Open(sFile, true))
        {
            MainDocumentPart myPart = wdDoc.MainDocumentPart;
            FooterPart newFtPart = myPart.AddNewPart<FooterPart>();
            string ft_ID = myPart.GetIdOfPart(newFtPart);

            MakeFooterPart(sFtText).Save(newFtPart);
            foreach (SectionProperties sectProperties in
                    myPart.Document.Descendants<SectionProperties>())
            {
                 FooterReference newFtReference =
                  new FooterReference() { Id = ft_ID, Type = HeaderFooterValues.Default };
                sectProperties.Append(newFtReference);
            }
            //  Save the changes to the main document part.
            myPart.Document.Save();
        }
    }

////////////////////////////////////

    private static Footer MakeFooterPart(string FooterText)
    {
        var element =
          new Footer(
            new Paragraph(
              new ParagraphProperties(
                new ParagraphStyleId() { Val = "Footer" }),
              new Run(
                new Text(FooterText))
            )
          );

        return element;
    }
4

0 回答 0