Hero is coming back

风吹呀吹

风会指引你前进的方向

C# NPOI

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();
    }
}
posted @ 2021-03-02 13:39  风吹呀吹  阅读(1004)  评论(1编辑  收藏  举报