从C#读取Excel文件 [英] Reading an Excel File From C#

查看:106
本文介绍了从C#读取Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  String ConnectionString = 提供者= Microsoft.ACE.OLEDB.12.0; + 
Data Source =+ VariableFile +; +
扩展属性= Excel 8.0;;

我也有objConn.Open();打开文件..



问题是我的程序打开文件的唯一时间是我手动打开Excel文件并运行我的程序。任何人都可以帮助我从我的C#代码打开文件,而不必首先手动打开它。我收到错误信息:无法找到可以运行它,而不打开Excel文件首先。



谢谢

解决方案

我认为您的连接字符串格式化错误,无法找到可安装的ISAM通常是这样的指示。



尝试这个,这是从我的一个操作代码:



Excel 2007

  string connectionString = string.Format(Provider = Microsoft.ACE.OLEDB.12.0; Data Source = {0};扩展属性= \Excel 12.0 Xml; HDR =否; IMEX = 1\;,fullPath); 

Excel 2003

 code> string connectionString = string.Format(Provider = Microsoft.Jet.OLEDB.4.0; data source = {0};扩展属性= \Excel 8.0; HDR =否; IMEX = 1\; , 完整路径); 


I have a connection string to read an excel file from my C# project that looks like this..

String ConnectionString  = "Provider=Microsoft.ACE.OLEDB.12.0;" +
                                      "Data Source=" + VariableFile + ";" +
                                      "Extended Properties=Excel 8.0;";

and I also have objConn.Open(); to open the file..

The problem is the only time my program will open the file is if I open the Excel file manually and run my program. Can anyone help me to open the file from my C# code instead of having to open it first manually. I get the error message: Could not find installable ISAM when I try to run it without opening the Excel file first.

Thank you

解决方案

I think your connection string is formatted wrong and the "Could not find installable ISAM" is usually an indication of this.

Try this, it's from a piece of operational code I have:

Excel 2007

string connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=No;IMEX=1\";", fullPath);

Excel 2003

string connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=\"Excel 8.0;HDR=No;IMEX=1\";", fullPath);

这篇关于从C#读取Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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