using System; using System.Collections.Generic; using System.IO; using System.Text; using Infrastructure.Abstructions; using NPOI.XWPF.UserModel; namespace Infrastructure.Word { public class Parser: IWordParser,ITransientDependency { public XWPFDocument ReadDocument(string path) { XWPFDocument document = null; if (!File.Exists(path)) { throw new Exception("文件不存在"); } using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read)) { document = new XWPFDocument(file); } return document; } public List> Parse(XWPFDocument document, IWordTableResolver resolver) { var result = new List>(); foreach (XWPFTable table in document.Tables) { var parseResult= resolver.Resolve(table); result.Add(parseResult); } return result; } } }