【问题标题】:Extract embedded table from doc(x) file .NET从 doc(x) 文件 .NET 中提取嵌入表
【发布时间】:2018-06-10 13:58:00
【问题描述】:

据我了解 - 最短的方法是将文件转换为 XML。这将允许按标签查找表。

var fileinfo = new FileInfo(@"c:\Users\a1oleg\Desktop\myFile.docx");                        

XDocument xml = null;
using (StreamReader oReader = new StreamReader(fileinfo.FullName)
{                
    xml = XDocument.Load(oReader);
}

错误是:

System.Xml.XmlException: '根级别的数据无效。第 1 行,位置 1。'

【问题讨论】:

  • docx 是一个压缩的 xml。所以首先需要解压。

标签: c# asp.net xml streamreader


【解决方案1】:

你可以使用 Microsoft.Office.Interop.Word

Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
Documents docs = app.Documents;
Document doc = docs.Open("C:\\users\\Test.docx", ReadOnly:true);
Table tbl = doc.Tables[1];
Range rg = tbl.Range;
Cells cells = rg.Cells;

【讨论】:

  • 与项目 - 属性 - 构建 - 目标平台:任何 CPU || x64 错误是:> System.Runtime.InteropServices.COMException:'检索具有 CLSID {000209FF-0000-0000-C000-000000000046} 的组件的 COM 类工厂失败,原因是以下错误:80040154 Класс не зарегистрирован(来自 HRESULT 的异常:0x80040154(REGDB_E_CLASSNOTREG))。使用 x86 退出调试,没有结果,没有到达代码后的断点。
  • 可以在此处找到此错误的答案-stackoverflow.com/questions/35284589/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-29
  • 1970-01-01
  • 2010-11-18
相关资源
最近更新 更多