NET 读取Word文档信息

1.添加程序集引用:WindowsBase

2.添加nuget:DocumentFormat.OpenXml

3.代码:

var wordPath = @"C:\xxx.docx";

using (WordprocessingDocument doc = WordprocessingDocument.Open(wordPath, true))
{
Body body = doc.MainDocumentPart.Document.Body;
foreach (var paragraph in body.Elements<Paragraph>())
{
Console.WriteLine(paragraph.InnerText);
txt.AppendLine(paragraph.InnerText);
}
}

4.word后缀不是:docx,会报错

posted @ 2018-08-28 14:13  Robot-Blog  阅读(983)  评论(1编辑  收藏  举报