我正在使用Open XML SDK 2.5在我的控制檯應用程序中讀取.docx
文件。DOCX XML不象Word那樣代表換行符?
在使用Open XML SDK打開Word時,Word顯示文檔的方式以及如何用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可以實現嗎?
在此先感謝。
完美!這正是我需要的。 對於任何想做同樣事情的人來說,在我的實現中,我只是將所有'Paragraph'的'Run'子元素和它們的'InnerText'屬性添加到單個字符串中,並在'Run '對象包含一個'Break'類型的子對象。 –