使用C#中的嵌入式Word文档读取Excel文件

时间:2011-07-06 21:15:28

标签: c# asp.net excel ms-word

所以现在我的ASP.net应用程序运行良好,我能够在这里读取Excel文件没什么好看的:

      string conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Sample.xls;Extended Properties=\"Excel 8.0;HDR=Yes\"";
      string SQLString = "SELECT * FROM [Sheet1$]";
      OleDbConnection DBConnection = new OleDbConnection(conString);
      OleDbCommand DBCommand = new OleDbCommand(sQuery, DBConnection);
      IDataReader iReader = DBCommand.ExecuteReader();

在此之后,我可以在DataGrid对象上显示电子表格,大多数单元格看起来都很好。

但是,此电子表格在某些单元格中包含嵌入的word文档。例如,如果我突出显示单元格,我会看到“= EMBED(”Word.Document.8“,”“)”并且单元格中有一个单词文档。

所以我的问题是有谁知道我如何访问这些嵌入的word文档?现在,单元格在我的DataGrid上显示为空。

1 个答案:

答案 0 :(得分:2)

我认为你无法用OLEDB做到这一点。您将不得不依赖COM Interop来获取数据。查看http://msdn.microsoft.com/en-us/library/ff597926.aspx