如何基于openxmlelement获取页码
对于Paragraph对象,如何使用Open XML SDK 2.5确定该对象位于哪一页上?
For a Paragraph object, how can I determine on which page this is located using the Open XML SDK 2.5 ?
我已经使用此方法在文档中获取了所有子元素,并还获取了内部文本.
I've obtained all child elements in my document and fetched innertext also, using this.
foreach (var i in mainPart.Document.ChildElements.FirstOrDefault().ChildElements)
{
ParagraphElements.Add(i); //openxmlelement list
}
我想获取相应段落的页码.例如,我将"this is heading 1"标记为样式Heading 1,并将在目录中对其进行更新.所以我需要传递页码
I want to get page number for corresponding paragraph. for example, I have "this is heading 1" marked as style Heading 1 and this will be updated in TOC. so there I need to pass page number
预先感谢
经过大量基础工作,我发现,页码无法使用openxml元素检索. 我们可以近似它.但是我们不能确定.因为页码是由文字处理器布局引擎呈现的.在所有OpenXML元素都传递给文字处理器之后,就会发生这种情况. 我们可以使用LastRenderedPageBreak进行计算.但是我们不能确定元素的位置是否正确.
After a lot of ground work, I found that, page number cannot be retrieved using openxml element. We can approximate it. But we cannot be sure. Because Page numbers are rendered by word processor layout engine. This happens after all the OpenXML elements are passed to word processor. We can calculate it with LastRenderedPageBreak. But we cannot be sure that location of the element is correct.
因此,我建议使用UpdateFieldsOnOpen或Macro以获得更简单的解决方案.
So, I would suggest to go with UpdateFieldsOnOpen or Macro for an easier solution.