如何使用OpenXML从段落中查找页码? [英] How to find the page number from a paragraph using OpenXML?
问题描述
对于段落对象,如何使用适用于Microsoft Office的Open XML SDK 2.0确定该对象位于哪个页面上?
For a Paragraph object, how can I determine on which page this is located using the Open XML SDK 2.0 for Microsoft Office ?
推荐答案
由于OpanXml Sdk
是由客户端(例如MS Word)处理的,因此无法使用OpanXml Sdk
获取Word文档的页码.
It is not possible to get page numbers for a word document using OpanXml Sdk
as this is handled by the client (like MS Word).
但是,如果您正在使用的文档先前是由单词客户端打开并保存回去的,则客户端将添加LastRenderedPageBreak
来标识分页符.请参阅我的答案此处,以获取有关LastRenderedPageBreak
的更多信息.这使您可以在段落之前计算LastRenderedPageBreak
元素的数量,以获取当前页数.
However if the document you are working with is previously opened by a word client and saved back, then the client will add LastRenderedPageBreak
to identify the page breaks. Refer to my answer here for more info about LastRenderedPageBreak
s. This enables you to count for the number of LastRenderedPageBreak
elements before your paragraph to get the current page count.
如果不是这种情况,那么满足您要求的noddy选项就是添加带有页码的页脚(可能与您的文档具有相同的颜色,以实际上隐藏它!).唯一的选择-如果要使用OpenXML sdk
自动生成Word文档.
If this is not the case then the noddy option to work around your requirement is to add footers with page numbers (may be with same colour as your documents to virtually hide it!). Only an option - if you are automating the word document generation using OpenXML sdk
.
这篇关于如何使用OpenXML从段落中查找页码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!