C# 为什么openxml页脚没有发布到文档

C# 为什么openxml页脚没有发布到文档,c#,ms-word,openxml,footer,C#,Ms Word,Openxml,Footer,我遵循了一些示例,但我无法使用openxml将页脚打印到字处理文档中。我打赌我在这里遗漏了一些琐碎的东西,但我就是看不见/找不到 MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); mainPart.Document = new Document(); Body docBody = mainPart.Document.AppendChild(new

我遵循了一些示例,但我无法使用openxml将页脚打印到字处理文档中。我打赌我在这里遗漏了一些琐碎的东西,但我就是看不见/找不到

            MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
            mainPart.Document = new Document();
            Body docBody = mainPart.Document.AppendChild(new Body());
            FooterPart footerPart = mainPart.AddNewPart<FooterPart>();
            string footerId = mainPart.GetIdOfPart(footerPart);

            SectionProperties sectionProperties = new SectionProperties();
            FooterReference footerReference = new FooterReference() { Id = footerId, Type = HeaderFooterValues.Default };sectionProperties.Append(footerReference);
            PageMargin pageMargin = new PageMargin() { Top = 1440, Right = (UInt32Value)1440U, Bottom = 1440, Left = (UInt32Value)1440U, Header = (UInt32Value)720U, Footer = (UInt32Value)1080U, Gutter = (UInt32Value)0U };
            sectionProperties.Append(pageMargin);

            Footer footer = new Footer();
            Paragraph paragraph50 = new Paragraph();
            ParagraphProperties footerProperties = new ParagraphProperties();

            footerProperties.Append(new ParagraphStyleId() { Val = "Footer" });
            footerProperties.Append(new Justification() { Val = JustificationValues.Both });
            footerProperties.Append(sectionProperties);
            paragraph50.Append(footerProperties);
            footer.Append(paragraph50);
            footerPart.Footer = footer;

            RunProperties frp = new RunProperties();
            frp.Color = new Color() { Val = "C0C0C0" };
            frp.FontSize = new FontSize() { Val = "15" };

            Run frun1 = new Run();
            frun1.Append(frp);
            frun1.Append(new Text("UNIFORM INSTRUMENT"));

            paragraph50.Append(frun1);
MainDocumentPart mainPart=wordDocument.AddMainDocumentPart();
mainPart.Document=新文档();
Body docBody=mainPart.Document.AppendChild(新的Body());
FooterPart FooterPart=mainPart.AddNewPart();
字符串footerId=mainPart.GetIdOfPart(footerPart);
SectionProperties SectionProperties=新的SectionProperties();
FooterReference FooterReference=new FooterReference(){Id=footerId,Type=HeaderFooterValues.Default};sectionProperties.Append(页脚引用);
PageMargin PageMargin=new PageMargin(){Top=1440,Right=(uint32值)1440U,Bottom=1440,Left=(uint32值)1440U,Header=(uint32值)720U,Footer=(uint32值)1080U,Footer=(uint32值)0U};
sectionProperties.Append(页边距);
页脚页脚=新页脚();
第50段=新段落();
ParagraphProperties footerProperties=新的ParagraphProperties();
Append(新段落样式ID(){Val=“Footer”});
Append(新的对正(){Val=justicationvalues.Both});
footerProperties.Append(sectionProperties);
第50段.附加(页脚属性);
脚注.附加(第50段);
footerPart.Footer=页脚;
RunProperties frp=新的RunProperties();
frp.Color=newcolor(){Val=“c0c0”};
frp.FontSize=新的FontSize(){Val=“15”};
Run frun1=新运行();
frun1.附加(frp);
frun1.附加(新文本(“统一文书”));
第50段。附加(frun1);

直接的问题是,当节属性应该附加到
docBody

i、 如果你改变了

        footerProperties.Append(sectionProperties);

然后,您应该能够打开生成的.docx并查看页脚


就我个人而言,我发现Office Open SDK生产力工具对于理解如何构建Word文档非常宝贵——我认为只有WIndows,但它是可用的下载之一

直接的问题是,当节属性应该附加到
文档正文

i、 如果你改变了

        footerProperties.Append(sectionProperties);

然后,您应该能够打开生成的.docx并查看页脚


就我个人而言,我发现Office Open SDK生产力工具对于理解如何构建Word文档非常宝贵—我认为仅限WIndows,但它是可用的下载之一

感谢您的帮助,这不是我唯一的错误,而是。。。核心错误是未能包含所需的命名空间declarations@Jim,我想知道这一点,但当我运行代码时,缺少名称空间定义似乎并不是一个问题,而且必要的定义(“w:,简而言之)也在输出中。但是我们到了!谢谢你的帮助,这不是我唯一的错误,但是。。。核心错误是未能包含所需的命名空间declarations@Jim,我想知道这一点,但当我运行代码时,缺少名称空间定义似乎并不是一个问题,而且必要的定义(“w:,简而言之)也在输出中。但是我们到了!