用C#打开Excel 2003电子表格。找不到可安装的ISAM。例外 [英] Open an Excel 2003 spreadsheet with C#. Could not find installable ISAM. Exception

查看:221
本文介绍了用C#打开Excel 2003电子表格。找不到可安装的ISAM。例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从xls中拉取数据,我还需要用户能够更改文件的位置。所以一个OleDbConnection似乎是一个好的开始,直到第一个合并的单元格。

I need to pull data from an xls, I also need have the user be able to change the location of the file it will. So an OleDbConnection seemed like a good start, and it was until the first merged cell.

这适用于除合并单元格之外的所有单元格:

This works for all but the merged cells:

OleDbCommand cmd = new OleDbCommand();
cmd.Connection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data 
Source=F:\test.xls;Extended Properties=Excel 8.0;");
cmd.CommandText = "SELECT * FROM [Sheet$]";
cmd.Connection.Open();

我发现这应该允许访问合并的单元格:

I found that this should allow access to the merged cells:

OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\test.xls;Extended Properties=Excel 8.0;HDR=Yes;IMEX=1;");

但是,我得到一个找不到可以在cmd.conn.open();

But then I get a Could not find installable ISAM exception on cmd.conn.open();

我遵循以下建议:
http://support.microsoft.com/kb/209805

此处:
错误:无法找到可安装的ISAM

没有运气

我可以从其他方式从xls中提取数据。或者即使有一个命令,我可以在xls上运行,以删除可能工作的mirged单元。

I’m open to other ways of pulling data from the xls. Or even if there was a command I could run on the xls to remove the mirged cells that might work.

推荐答案

我认为这是只要您有多个引号将扩展属性括起来,如果您有多个

I think it's just because you have to enclose the Extended Properties in quotes if you have more than one

OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\test.xls;
Extended Properties='Excel 8.0;HDR=Yes;IMEX=1';");

或者如果单引号不起作用(你得到想法)

Or if single quotes don't work (you get the idea)

OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\test.xls;
Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1;"";");

虽然您的示例未显示,但此错误也可能由文件路径中的空格引起。在这种情况下,您还需要将文件路径包含在引号中。

While your example doesn't show it, this error can also be caused by spaces in the file path. In which case you would need to wrap the file path in quotes as well.

OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""F:\test.xls"";...

这篇关于用C#打开Excel 2003电子表格。找不到可安装的ISAM。例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆