c# oldb连接_oledb连接字符串为excel 2016在c#

I have been trying to access 2016 ms Excel file using c#, but connection string is working only till 2013 ms excel.

my current connection string:

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx;

Extended Properties="Excel 12.0 Xml;HDR=YES";

is there any modified oledb connection string for ms excel 2016?

any help would be appreciable, thanks in advance.

解决方案

This occurred for me after upgrading from a local install of Office 13 to Office 16 through the Office 365 program. I was getting this exception: The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

I was not able to find a way to install the driver through the office 365 install process.

I had to install https://www.microsoft.com/en-us/download/details.aspx?id=13255 - the x64 version did not solve the issue, had to use the 32bit version.

My connection string in App.config

Code using it:

var excelConnectionString = ConfigurationSettings.GetExcelConnection(fileLocation);

var dataTable = new DataTable();

using (var excelConnection = new OleDbConnection(excelConnectionString))

{

excelConnection.Open();

var dataAdapter = new OleDbDataAdapter("SELECT * FROM [Users$]", excelConnection);

dataAdapter.Fill(dataTable);

excelConnection.Close();

}

Console.WriteLine("OpenExcelFile: File successfully opened:" + fileLocation);

return dataTable;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值