从C#读取Excel工作表时出错:
错误[IM002] [Microsoft] [ODBC驱动程序管理器]未找到数据源名称且未指定默认驱动程序
如何解决这个问题?
这是我的代码:
OdbcConnection oConn = new OdbcConnection();
oConn.ConnectionString =
"Provider=MSDASQL.1;data source=D:\\Para_Lalit\\sample.xlsx;Extended Properties='Excel 12.0;Format=xlsx'";
OdbcCommand oComm = new OdbcCommand();
oComm.Connection = oConn;
oComm.CommandText = "Select * From [aa$]";
try
{
DataSet ds = new DataSet();
OdbcDataAdapter oAdapter = new OdbcDataAdapter(oComm);
oConn.Open();
oAdapter.Fill(ds);
dataGridView1.DataSource = ds;
dataGridView1.DataBind();
dataGridView1.DataMember = ds.Tables[0].TableName;
}
答案 0 :(得分:0)
查看一个名为OfficeOpenXML的dll,有一个opensource excel包可以下载来操作Excel文件