如何使用OpenXML从段落中查找页码? [英] How to find the page number from a paragraph using OpenXML?

查看:262
本文介绍了如何使用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 LastRenderedPageBreaks. 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屋!

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