C# 如何通过编程更改Word 2010文档的布局?

C# 如何通过编程更改Word 2010文档的布局?,c#,.net,ms-word,C#,.net,Ms Word,我们有一个应用程序,可以读取Word文档并将它们导入到我们的文件格式中 最近发现一个错误,页面计数仅在页面布局视图中可用,但Word 2010默认为Web布局 使用.NET c#如何更改视图以返回页数?我相信您要查找的属性是Document.ActiveWindow.view.Type=wdPrintView您可以在本页阅读更多内容。在发布答案时,您不应仅提供代码块,还应解释其工作原理以及如何解决原始问题。 //Here is my code snipped based on 'Document

我们有一个应用程序,可以读取Word文档并将它们导入到我们的文件格式中

最近发现一个错误,页面计数仅在页面布局视图中可用,但Word 2010默认为Web布局


使用.NET c#如何更改视图以返回页数?

我相信您要查找的属性是
Document.ActiveWindow.view.Type=wdPrintView
您可以在本页阅读更多内容。

在发布答案时,您不应仅提供代码块,还应解释其工作原理以及如何解决原始问题。
//Here is my code snipped based on 'DocumentFormat.OpenXml' nuget package.

//Open doc file
using (var wordDocument = WordprocessingDocument.Open(strInputFile,true))
             {
                 SectionProperties sectionProps = new SectionProperties();
//Set page margins
                 PageMargin margin = new PageMargin() { Top = 1008, 
                                                            Right = (UInt32Value)1008U, 
                                                            Bottom = 1008, 
                                                            Left = (UInt32Value)1008U, 
                                                            Header = (UInt32Value)720U, 
                                                            Footer = (UInt32Value)720U, `enter code here`
                                                            Gutter = (UInt32Value)0U };
                 sectionProps.Append(margin);
                 //Apply margin
wordDocument.MainDocumentPart.Document.Body.Append(sectionProps);
//Save changes
                 wordDocument.Save();
 }