代码之家  ›  专栏  ›  技术社区  ›  a1oleg

从Doc(x)文件.net中提取嵌入表

  •  0
  • a1oleg  · 技术社区  · 7 年前

    据我所知,最短的方法是将文件转换为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'

    1 回复  |  直到 7 年前
        1
  •  0
  •   Prany    7 年前

    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;
    
    推荐文章