如何使用Open XML SDK获得MS Word的总页数? [英] How to get MS Word total pages count using Open XML SDK?

查看:148
本文介绍了如何使用Open XML SDK获得MS Word的总页数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下面的代码来获取页数,但它没有给出实际的页数(PFA).获得总页数的更好方法是什么?

I am using below code to get the page count but it is not giving actual page count(PFA). What is the better way to get the total pages count?

var pageCount = doc.ExtendedFilePropertiesPart.Properties.Pages.Text.Trim();

注意:我们不能在我的Azure Web应用程序服务中使用Office主互操作程序集

Note: We cannot use the Office Primary Interop Assemblies in my Azure web app service

谢谢.

推荐答案

理论上,以下属性可以使用Open XML SDK从Word Open XML文件返回该信息:

In theory, the following property can return that information from the Word Open XML file, using the Open XML SDK:

int pageCount = (int) document.ExtendedFilePropertiesPart.Properties.Pages.Text;

但是,在实践中,这是不可靠的.它可能会起作用,但又可能不起作用-都取决于1)Word在关闭文件之前设法保存在文件中的内容,以及2)可能对关闭的文件进行了什么样的编辑.

In practice, however, this isn't reliable. It might work, but then again, it might not - it all depends on 1) What Word managed to save in the file before it was closed and 2) what kind of editing may have been done on the closed file.

获取页码或页数的唯一确定的方法是在Word应用程序界面中打开文档.页数和页数是在Word编辑过程中动态计算的.关闭文档时,此信息是静态的,不一定是打开或打印文档时的信息.

The only sure way to get a page number or a page count is to open a document in the Word application interface. Page count and number of pages is calculated dynamically, during editing, by Word. When a document is closed, this information is static and not necessarily what it will be when the document is open or printed.

另请参见 https://github.com/OfficeDev/Open-XML -SDK/issues/22 进行确认.

这篇关于如何使用Open XML SDK获得MS Word的总页数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆