【发布时间】:2023-03-24 22:16:01
【问题描述】:
我正在使用 Open XML SDK 2.5 在我的控制台应用程序中读取 .docx 文件。
Word 显示文档的方式与使用 Open XML SDK 打开时文档在 XML 中的表示方式之间似乎存在一些差异。
这是我在 Word 中看到的示例,其中空格可见:
所以在我的应用程序中,我将此段落作为DocumentFormat.OpenXml.Wordprocessing.Paragraph 对象引用。浏览 Open XML 文档后,我清楚地知道在 XML 格式中没有“线”的表示。所以我能做的最好的就是拥有我的Paragraph,最接近一条线的是Run 对象。在此示例中,Paragraph 节点具有 6 个 Run 对象的集合。如果我在此示例中获得Paragraph 的InnerXml 属性,它的外观如下:
<w:pPr xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:pStyle w:val=\"PlainText\" /><w:numPr><w:ilvl w:val=\"0\" /><w:numId w:val=\"17\" /></w:numPr><w:rPr><w:rFonts w:ascii=\"Arial\" w:hAnsi=\"Arial\" /><w:b /></w:rPr></w:pPr><w:r w:rsidRPr=\"000558F8\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:rPr><w:rFonts w:ascii=\"Arial\" w:hAnsi=\"Arial\" /></w:rPr><w:t>Should we use the term “Verify” instead of “Confirm”</w:t></w:r><w:r w:rsidRPr=\"000558F8\" w:rsidR=\"00F5335C\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:rPr><w:rFonts w:ascii=\"Arial\" w:hAnsi=\"Arial\" /></w:rPr><w:t xml:space=\"preserve\"> as per work instruction</w:t></w:r><w:r w:rsidRPr=\"000558F8\" w:rsidR=\"00411638\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:rPr><w:rFonts w:ascii=\"Arial\" w:hAnsi=\"Arial\" /></w:rPr><w:t>?</w:t></w:r><w:r w:rsidR=\"000558F8\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:rPr><w:rFonts w:ascii=\"Arial\" w:hAnsi=\"Arial\" /></w:rPr><w:br /><w:t>Med</w:t></w:r><w:r w:rsidRPr=\"000558F8\" w:rsidR=\"003E76BD\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:rPr><w:rFonts w:ascii=\"Arial\" w:hAnsi=\"Arial\" /><w:b /></w:rPr><w:br /><w:t xml:space=\"preserve\">JD: </w:t></w:r><w:r w:rsidRPr=\"000558F8\" w:rsidR=\"00A118AB\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:rPr><w:rFonts w:ascii=\"Arial\" w:hAnsi=\"Arial\" /><w:b /></w:rPr><w:t>Done.</w:t></w:r>
我看到的只是段落属性节点和 6 个运行节点。如您所见,运行节点不等于线。从 Word 中查看我的示例,我看到该段落有 2 个回车符,我希望这由 3 个“行”表示。然而,在 XML 中,我得到了 6 次运行,这似乎与 3 行非常接近,但由于某种原因,有些行似乎是任意拆分的。
真正的问题是,我看不到任何解释运行节点的方式,我可以重建 Word 示例中的行结构。例如,没有任何迹象表明运行 1、2 和 3 一起构成了第 1 行。
我需要解析超过 300 个单词的文档,这些文档依赖于换行符进行格式化。我需要换行符,我怎样才能得到它们?这可以通过 Open XML SDK 实现吗?
提前致谢。
【问题讨论】:
标签: xml ms-word openxml docx openxml-sdk