OpenXml读取word内容注意事项

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

2、需要引入相关dll;"WindowsBase.dll"、“DocumentFormat.OpenXml.dll”;

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

word内容

OpenXml读取word内容注意事项

相关代码

OpenXml读取word内容注意事项

 

OpenXml读取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内容注意事项

相关文章:

  • 2021-10-20
  • 2022-12-23
  • 2021-11-15
  • 2021-11-15
  • 2022-12-23
  • 2022-02-17
猜你喜欢
  • 2017-12-20
  • 2021-12-30
  • 2022-02-01
  • 2021-04-30
  • 2022-12-23
相关资源
相似解决方案