OpenXml讀取word內(nèi)容注意事項
1、使用OpenXml讀取word內(nèi)容,word后綴必須是".docx";如果word后綴是".doc"需要轉(zhuǎn)成".docx"后,才可以讀取;
2、需要引入相關(guān)dll;"WindowsBase.dll"、“DocumentFormat.OpenXml.dll”;
3、word大小>0字節(jié)(word大小為0字節(jié)會報錯);
word內(nèi)容

相關(guān)代碼
 
static void Main(string[] args)  {   string wordPathStr = @"C:/Users/user/Desktop/新建文件夾 (2)/5.docx";   using (WordprocessingDocument doc = WordprocessingDocument.Open(wordPathStr, true))   {    Body body = doc.MainDocumentPart.Document.Body;    foreach (var paragraph in body.Elements<Paragraph>())    {     Console.WriteLine(paragraph.InnerText);    }   }   Console.ReadLine();  }控制臺顯示

以上這篇OpenXml讀取word內(nèi)容的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持武林網(wǎng)。
 
  | 
新聞熱點
疑難解答