消防站文档解析
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.1 KiB

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<Dictionary<string,object >> Parse(XWPFDocument document, IWordTableResolver resolver)
{
var result = new List<Dictionary<string, object>>();
foreach (XWPFTable table in document.Tables)
{
var parseResult= resolver.Resolve(table);
result.Add(parseResult);
}
return result;
}
}
}