C# 导入Excel 2013到vs,本地机器上没有注册Microsoft ACE.OLEDB.12.0

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16610940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 01:27:50  来源:igfitidea点击:

Import Excel 2013 to vs, Microsoft ACE.OLEDB.12.0 is not registered on the local Machine

c#excelms-accessjet

提问by Arantuath

Creating a form application in vs 2012. I have office 2013 installed, win 8 64 bit. I get the above error for the below piece of code.

在 vs 2012 中创建表单应用程序。我安装了 office 2013,win 8 64 位。我收到以下代码的上述错误。

public void SetConnection(string text1, string text2, string text3, string text4, string text5, string text6, string text7)
    {
        connectionString1 = "Initial Catalog=test; Data Source=work\sqlexpress";
        connectionString = "Data Source='c:\Users\test1.xlsx';Extended Properties=Excel 12.0 Xml;Readonly=False;";
        database = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" + connectionString);
        database.Open();
        database1 = new OleDbConnection("Provider=SQLOLEDB.1;" + connectionString1);
        database1.Open();
    }

I tried using jet drivers but would not work, so i turned to ace. First i got "Cannot find installable ISAM"; so installed AccessDatabaseEngine_x64 which leads me to this error. I then changed my build to x86 and same errors. So i'm out of options. I did try previous versions of AccessDatabaseEngine from 2007 and 2010 but no luck, any suggestions.

我尝试使用喷气式驱动程序但不起作用,所以我转向 ace。首先我得到“无法找到可安装的 ISAM”;所以安装了 AccessDatabaseEngine_x64 这导致我出现这个错误。然后我将构建更改为 x86 和相同的错误。所以我别无选择。我确实尝试过 2007 年和 2010 年以前版本的 AccessDatabaseEngine,但没有任何建议。

采纳答案by Arantuath

database = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\Users\test.xls';Extended Properties= \"Excel 8.0;HDR=Yes;IMEX=1\";");

The above connection string works using jet although i have to leave the excel file open for the time being as i get "could not decrypt file" error otherwise. I also had to save the file as a 97-03 excel xls file.

上面的连接字符串使用 jet 工作,尽管我必须暂时打开 excel 文件,否则我会收到“无法解密文件”错误。我还必须将文件另存为 97-03 excel xls 文件。

回答by user3026216

string connectionString = "Provider=Microsoft.Jet.OleDb.4.0;Extended Properties=Excel 12.0 Xml;HDR=YES; Data Source=C:\Users\q\Desktop\Ug\Test.xlsx";

string connectionString = "Provider=Microsoft.Jet.OleDb.4.0;扩展属性=Excel 12.0 Xml;HDR=YES;数据源=C:\Users\q\Desktop\Ug\Test.xlsx";

回答by Alexander Y.

As said here, probably you have the 64-bit office installed which doesn't have the 32-bit compnents installed (links are provided there). You may also have to biuld your project targetint x86 platform.

至于说在这里,也许你有64位Office安装不安装32位compnents(提供有链接)。您可能还需要构建您的项目 targetint x86 平台。