如何将页码添加到WordProccesingDocument OpenXml C#

时间:2015-07-29 14:35:19

标签: c# openxml page-numbering

public static void AddNumeration(ref WordprocessingDocument finalDoc)         {

        IEnumerable<FooterPart> foo = finalDoc.MainDocumentPart.FooterParts;

        int count = 1;
        foreach (FooterPart fp in foo){

        Footer f = new Footer();

        ParagraphProperties paragraphProperties1 = new ParagraphProperties(new SectionProperties(new PageNumberType { Start = 1 }));
        paragraphProperties1.NumberingProperties = NumberingProperties
        paragraphProperties1.Justification = new Justification() { Val = JustificationValues.Right };
        Run run1 = new Run();
        Text text1 = new Text();

        text1.Text = count.ToString();
        count++;
        run1.Append(text1);
        Paragraph paragraph1 = new Paragraph() { RsidParagraphAddition = "00164C17", RsidRunAdditionDefault = "00164C17" };

        paragraph1.Append(paragraphProperties1);
        paragraph1.Append(run1);

        f.Append(paragraph1);

        fp.Footer = f;
     }


    }

此代码始终在每页的页脚部分显示数字1。

1 个答案:

答案 0 :(得分:-1)

在Google上进行一点点搜索:https://janewdaisy.wordpress.com/2012/03/01/insert-footer-in-word-document-cvb-net/

它应该做的工作