当前位置: 移动技术网 > IT编程>开发语言>c# > OpenXml读取word内容的实例

OpenXml读取word内容的实例

2019年07月18日  | 移动技术网IT编程  | 我要评论
openxml读取word内容注意事项 1、使用openxml读取word内容,word后缀必须是".docx";如果word后缀是".doc"需要转成".docx"后,

openxml读取word内容注意事项

1、使用openxml读取word内容,word后缀必须是".docx";如果word后缀是".doc"需要转成".docx"后,才可以读取;

2、需要引入相关dll;"windowsbase.dll"、“documentformat.openxml.dll”;

3、word大小>0字节(word大小为0字节会报错);

word内容

相关代码

 

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内容的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网