在C#中读取xlsx档案使用的OleDbConnection会抛出错误 [英] Reading xlsx file in c# using OleDbConnection throws error

查看:314
本文介绍了在C#中读取xlsx档案使用的OleDbConnection会抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个控制台应用程序读取在C#中使用的OleDbConnection XLSX 文件。它引发以下错误

I wrote a console application to read the xlsx file in C# using OleDbConnection. It throws the following error

'提供者未在本地机器上注册该Microsoft.ACE.OLEDB.12.0

The Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

下面是我写

string connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\Suganya\ColumnReport.xlsx;Extended Properties=Excel 12.0;";
OleDbConnection objConn = new OleDbConnection();
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
objConn = new OleDbConnection(connString);

string Query = "SELECT * FROM [Sheet1$]";
OleDbCommand objCmd = new OleDbCommand(Query, objConn);

DataTable Table = new DataTable();
dataAdapter.SelectCommand = objCmd;
dataAdapter.Fill(Table);



我已执行下面的东西来解决该问题。

I have already performed following things to fix the issue.


  1. 我已经安装了 AccessDatabaseEngine.exe (32位),发现 ACEOLEDB.dll 存在于以下路径 C:\Program文件(x86)\Common Files\microsoft shared\OF​​FICE14

  1. I have installed AccessDatabaseEngine.exe (32 bit) and found that ACEOLEDB.dll is present in the following path C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14

试图在应用程序中引用 ACEOLEDB.dll 。但它给了我下面的错误

Tried referring the ACEOLEDB.dll in the application. But it gave me the following error

不能添加到'ACEOLEDB.DLL'的引用。请确保该文件是可访问的,而且它是一个有效的集会或COM组件

A reference to 'ACEOLEDB.DLL' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component

控制台的配置平台应用是32位的

  • The configuration platform of console application is of 32 Bit

    环境细节


    1. 的Windows Server 2008(64位)

    2. Visual Studio 2010中(32位)

    3. MS办公室未安装

    经过以下几个环节来解决该问题。

    Checked the following links to fix the issue

    1的 http://www.codeproject.com/Questions/486549/Theplus- 27Microsoft-ACE-OLEDB的12-0-27plusproviderp
    2的 http://www.codeproject.com/Questions/337953/The-Microsoft-ACE-OLEDB-12-0-provider-is-not-regis

    任何帮助,高度赞赏。

    推荐答案

    您必须安装Microsoft Office; Office安装过程将在GAC复制和注册希望组件('ACEOLEDB.DLL'),或者你可以在你的bin(应用程序)目录添加缺少的组件或你的自我值寄存器他们。

    You have to install Microsoft Office; Office installation process will copy and register the wished assemblies ('ACEOLEDB.DLL') in the GAC, or you can add the missing assemblies in your bin (application) directory or regsiter them by your self.

    这篇关于在C#中读取xlsx档案使用的OleDbConnection会抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆