【发布时间】:2016-10-12 07:29:57
【问题描述】:
使用OpenXML,我可以通过页码读取文档内容吗?
wordDocument.MainDocumentPart.Document.Body 给出完整文档的内容。
public void OpenWordprocessingDocumentReadonly()
{
string filepath = @"C:\...\test.docx";
// Open a WordprocessingDocument based on a filepath.
using (WordprocessingDocument wordDocument =
WordprocessingDocument.Open(filepath, false))
{
// Assign a reference to the existing document body.
Body body = wordDocument.MainDocumentPart.Document.Body;
int pageCount = 0;
if (wordDocument.ExtendedFilePropertiesPart.Properties.Pages.Text != null)
{
pageCount = Convert.ToInt32(wordDocument.ExtendedFilePropertiesPart.Properties.Pages.Text);
}
for (int i = 1; i <= pageCount; i++)
{
//Read the content by page number
}
}
}
MSDN Reference
更新 1:
看起来分页符设置如下
<w:p w:rsidR="003328B0" w:rsidRDefault="003328B0">
<w:r>
<w:br w:type="page" />
</w:r>
</w:p>
所以现在我需要使用上述检查拆分 XML,并为每个检查使用 InnerTex,这将给我页面虎钳文本。
现在的问题是如何使用上述检查拆分 XML?
更新 2:
仅当您有分页符时才设置分页符,但如果文本从一页浮动到其他页面,则没有设置分页符 XML 元素,因此它返回到如何识别分页符的相同挑战.
【问题讨论】:
-
@PaulZahra 我在 XML 中找不到这样的元素(lastRenderedPageBreak)
标签: c# xml openxml docx openxml-sdk