C# NPOI

2021-03-05 00:25

阅读:548

标签:ocx   string   foreach   project   void   stream   cto   ring   str   

C# NPOI

Word

环境准备

Nuget安装

  • NPOI
  • NPOI.HWPF【读取doc文件,docx无法读取】

引用

using NPOI.HWPF;
using NPOI.HWPF.Extractor;

读取word文件

static void NPOIReadWord() {
    string path = @"D:\Project\NPOI_文本对比\PDF\1-太平粤港澳大湾区终身重大疾病保险条款.doc";
    using (StreamReader streamReader = new StreamReader(path))
    {
        var document = new HWPFDocument(streamReader.BaseStream);
        var wordExtractor = new WordExtractor(document);
        var docText = new StringBuilder();

        foreach (string text in wordExtractor.ParagraphText)
        {
            Console.WriteLine(text.Trim());
        }
        streamReader.Close();
    }
}

C# NPOI

标签:ocx   string   foreach   project   void   stream   cto   ring   str   

原文地址:https://www.cnblogs.com/tangpeng97/p/14468489.html


评论


亲,登录后才可以留言!