源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

OpenXml读取word内容的实例

  • 时间:2022-02-26 23:33 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:OpenXml读取word内容的实例
[b]OpenXml读取word内容注意事项[/b] 1、使用OpenXml读取word内容,word后缀必须是".docx";如果word后缀是".doc"需要转成".docx"后,才可以读取; 2、需要引入相关dll;"WindowsBase.dll"、“DocumentFormat.OpenXml.dll”; 3、word大小>0字节(word大小为0字节会报错); [b]word内容[/b] [img]http://files.jb51.net/file_images/article/201712/201712120856106.png[/img] [b]相关代码[/b] [img]http://files.jb51.net/file_images/article/201712/201712120856107.png[/img]  
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();
  }
[b]控制台显示[/b] [img]http://files.jb51.net/file_images/article/201712/2017121208561010.png[/img] 以上这篇OpenXml读取word内容的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部