我正在尝试使用OLEDB连接更新格式为“ xlsx”的Excel工作表中的某些数据,但是我无法确定连接的建立。
这是我的代码:
String sConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source='" + "D:\abc1.xlsx" + "';Extended Properties='Excel 8.0;HDR=Yes'";
OleDbConnection con = new OleDbConnection(sConnectionString);
con.Open();
OleDbCommand com = new OleDbCommand("select * from Sheet1",con);
OleDbDataReader reader = null;
reader = com.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader[0]);
}
con.Open();
Console.ReadLine();
}
运行代码时,我面临以下异常:
“ Microsoft.ACE.OLEDB.12.0”提供程序未在本地计算机上注册。
建议任何想法如何从此异常中恢复或我可以从Excel中更新数据的任何其他建议。
这可能是您说过的提供程序,尝试将其更改为与计算机上的Excel版本匹配的提供程序
尝试
Provider=Microsoft.ACE.OLEDB.12.0;Data Source='D:\abc1.xlsx';Extended Properties="Excel 12.0 Xml;HDR=YES";
代替
也可能是未安装excel
还要检查您是否已为项目引用了OLEDB库
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句