AspNet 读取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,会报错

猜你喜欢

转载自www.cnblogs.com/Cailf/p/9547936.html