从 Excel 读取:64 位系统上的 Microsoft.Jet.OLEDB.4.0 错误
我正在我的应用程序中使用以下内容读取 Excel 工作表的内容:
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties=Excel 8.0");
_myDataSet = new DataSet();
OleDbDataAdapter myCommand = new OleDbDataAdapter(" SELECT * FROM [" + "My Sheet" + "$]", con);
myCommand.Fill(_myDataSet);
con.Close();
这在 64 位系统中失败,并出现以下错误:
Microsoft.Jet.OLEDB.4.0' 提供商是 未在本地计算机上注册
如何使其在 64 位计算机上工作?
I am reading the contents of an excel sheet in my application using:
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties=Excel 8.0");
_myDataSet = new DataSet();
OleDbDataAdapter myCommand = new OleDbDataAdapter(" SELECT * FROM [" + "My Sheet" + "$]", con);
myCommand.Fill(_myDataSet);
con.Close();
This is failing in 64 bit systems with the error:
Microsoft.Jet.OLEDB.4.0' provider is
not registered on the local machine
How to make this work in 64 bit machines?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Microsoft 发布了包含适用于 Access 和 Excel 的 64 位驱动程序的驱动程序发行版。您可以从 MS 下载 64 位和 32 位版本 下载网站。下载页面还简要概述了您需要在连接字符串中更改哪些内容才能引用 ACE 驱动程序。
简而言之,您安装 64 位驱动程序发行版,然后将连接字符串更改为以下内容:
Microsoft released a driver distribution with a 64-bit driver that works for Access and Excel. You can download both the 64-bit and 32-bit versions from the MS downloads site. The download page also has a brief outline of what you would need to change in your connection string to reference the ACE driver.
In a nutshell, you install the 64-bit driver distribution and then change your connection string to something along the lines of:
Microsoft.Jet.OLEDB没有64位版本,只有32位版本。将应用程序编译为 32 位(平台目标:构建选项中的 x86)。
Microsoft.Jet.OLEDB doesn't have 64bit version, only 32bit. Compile your application as 32bit (Platform target: x86 in build option).
我不相信它有效...请参阅此相关问题:64位不支持OleDB模式?
问题似乎是 COM/Interop 不是为 64 位环境设计的,因此无法在 64 位模式下注册。
您可以强制 .NET 应用程序在 64 位计算机上以 32 位模式运行,这将允许您访问 OleDB 功能。
I don't believe it works... see this related question: OleDB not supported in 64bit mode?
The problem seems to be that the COM/Interop is not designed for 64 bit environments, and so it can't be registered in 64 bit mode.
You can force your .NET app to run in 32 bit mode on the 64 bit machine, which will allow you to access the OleDB functionality.
算了,使用codeplex的这些dll来解决这个问题吧。 http://exceldatareader.codeplex.com/
Forget it, use these dll from codeplex that solve this problem. http://exceldatareader.codeplex.com/