openxml讀取word內容注意事項
1、使用openxml讀取word內容,word后綴必須是".docx";如果word后綴是".doc"需要轉成".docx"后,才可以讀?。?/p>
2、需要引入相關dll;"windowsbase.dll"、“documentformat.openxml.dll”;
3、word大小>0字節(word大小為0字節會報錯);
word內容
相關代碼
1
2
3
4
5
6
7
8
9
10
11
12
13
|
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內容的實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持服務器之家。
原文鏈接:http://www.cnblogs.com/HYJ0201/archive/2017/12/12/8025760.html