C#操作EXCEL文件另一个问题
public DataSet ExcelToDS(string path)
{
string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;"
+ "DataSoure=" + path + ";"
+ "Extend Properties=Excel 8.0;HDR=NO;IMEX=1";
OleDbConnection conn = new OleDbConnection(connStr);
conn.Open();
string cmdStr = "select * from [sheet1$]";
OleDbDataAdapter adapter = new OleDbDataAdapter(cmdStr, conn);
DataSet ds = new DataSet();
adapter.Fill(ds);
return ds;
}
程序跑到conn.OPen();的时候就发生异常;
异常信息:
未处理
System.Data.OleDb.OleDbException
HResult=-2147467259
Message=找不到可安装的 ISAM。
Source=Microsoft JET Database Engine
ErrorCode=-2147467259
StackTrace:
在 System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
在 System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
在 System.Data.ProviderBase.DbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
在 System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
在 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
在 System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
在 System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
&nbs