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内容的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:http://HdhCmsTestcnblogs测试数据/HYJ0201/archive/2017/12/12/8025760.html
dy("nrwz");
查看更多关于OpenXml读取word内容的实例的详细内容...