如何以编程方式更改 Word 2010 文档的布局?

发布于 2024-10-06 03:22:05 字数 136 浏览 0 评论 0原文

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

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

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

We have an application that reads Word documents and imports them into our file format.

A recent bug was found that the page count is only available in Page Layout View, however Word 2010 defaults to Web Layout.

Using .NET c# how can we change the view to give us back the page count?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

路还长,别太狂 2024-10-13 03:22:05

我相信您正在寻找的属性是 Document.ActiveWindow.View.Type = wdPrintView; 您可以在 MSDN

I believe the property you are looking for is Document.ActiveWindow.View.Type = wdPrintView; You can read more in this on MSDN.

痴者 2024-10-13 03:22:05
//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();
 }
//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();
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文