1.添加程式集引用:WindowsBase 2.添加nuget:DocumentFormat.OpenXml 3.代碼: var wordPath = @"C:\xxx.docx"; using (WordprocessingDocument doc = WordprocessingDocument ...
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,會報錯