积极答复者
C# Excel ODBC & OLE 都说加载错误。

问题
-
我通过以下方式连接Excel文件,但都报:“未能加载文件或程序集“OfficeOperation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项。试图加载格式不正确的程序。”
求救是何原因?哪里可以当odbc驱动或OLE驱动?Windows7+openoffice(没有装过ms office),环境VS2010。
using System.Data;
using System.Data.OleDb;
using System.Data.Odbc;
FileName代表 excel文件路径。
/* OLE Part
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FilePath + ";Extended Properties='Excel 8.0;HDR=False;IMEX=1'";
Connection = new OleDbConnection(strConn);
Command = new OleDbCommand();
Command.Connection=Connection;
*/
OdbcConnection Connection = new OdbcConnection();
//Connection.ConnectionString = "Driver={Microsoft Excel Driver (*.xls)};DBQ=" + FileName;
Connection.ConnectionString = "Dsn=Excel Files;dbq=" + FileName + ";driverid=790;maxbuffersize=2048;pagetimeout=5";
OdbcCommand Command = new OdbcCommand();
Command.Connection = Connection;
try
{
Connection.Open();
}
catch (Exception e)
{
switch (e.Message)
{
case "外部表不是预期的格式。":
Error = e.Message;
break;
}// end catch (Exception e)
}谢谢。
答案
-
你好
或者你可以在以下URL Download Office Data Connectivity Components
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=7554F536-8C28-4598-9B72-EF94E038C891
Please correct me if my concept is wrong
Chi- 已标记为答案 BoberSongModerator 2010年10月5日 6:05
全部回复
-
我通过以下方式连接Excel文件,但都报:“未能加载文件或程序集“OfficeOperation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项。试图加载格式不正确的程序。”
求救是何原因?哪里可以当odbc驱动或OLE驱动?Windows7+openoffice(没有装过ms office),环境VS2010。
using System.Data;
using System.Data.OleDb;
using System.Data.Odbc;
FileName代表 excel文件路径。
/* OLE Part
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FilePath + ";Extended Properties='Excel 8.0;HDR=False;IMEX=1'";
Connection = new OleDbConnection(strConn);
Command = new OleDbCommand();
Command.Connection=Connection;
*/
OdbcConnection Connection = new OdbcConnection();
//Connection.ConnectionString = "Driver={Microsoft Excel Driver (*.xls)};DBQ=" + FileName;
Connection.ConnectionString = "Dsn=Excel Files;dbq=" + FileName + ";driverid=790;maxbuffersize=2048;pagetimeout=5";
OdbcCommand Command = new OdbcCommand();
Command.Connection = Connection;
try
{
Connection.Open();
}
catch (Exception e)
{
switch (e.Message)
{
case "外部表不是预期的格式。":
Error = e.Message;
break;
}// end catch (Exception e)
}谢谢。
用VS2010的数据向导,选择ODBC,选择Excel文件,选择xls文件名,选择表名;最后报“未能获取名为“`H:\资料\账本`..`jcyb$_`”的数据库对象的列信息。”其中jcyb是sheet名,它能看到sheet名,怎么还会报错呢? -
你好
或者你可以在以下URL Download Office Data Connectivity Components
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=7554F536-8C28-4598-9B72-EF94E038C891
Please correct me if my concept is wrong
Chi- 已标记为答案 BoberSongModerator 2010年10月5日 6:05