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();
}
}