C# 中 Excel 2016 的 oledb 连接字符串
oledb connection string for Excel 2016 in C#
我一直在尝试使用 C# 访问 2016 MS Excel 文件,但连接字符串仅在 2013 MS Excel.
之前有效
我当前的连接字符串:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx;
Extended Properties="Excel 12.0 Xml;HDR=YES";
MS Excel 2016 是否有修改过的 oledb 连接字符串?
这对我有用:
private string ExcelConnection(string fileName)
{
return @"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data Source=" + fileName + ";" +
@"Extended Properties=" + Convert.ToChar(34).ToString() +
@"Excel 8.0" + Convert.ToChar(34).ToString() + ";";
}
我在通过 Office 365 程序从本地安装的 Office 13 升级到 Office 16 后发生了这种情况。我收到此异常:'Microsoft.ACE.OLEDB.12.0' 提供程序未在本地计算机上注册。
我找不到通过 Office 365 安装过程安装驱动程序的方法。
我不得不安装 https://www.microsoft.com/en-us/download/details.aspx?id=13255 - x64 版本没有解决问题,不得不使用 32 位版本。
我的连接字符串在 App.config
<add key="Excel07ConnectionString" value="Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR=YES'"/>
使用它的代码:
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;
我一直在尝试使用 C# 访问 2016 MS Excel 文件,但连接字符串仅在 2013 MS Excel.
之前有效我当前的连接字符串:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx; Extended Properties="Excel 12.0 Xml;HDR=YES";
MS Excel 2016 是否有修改过的 oledb 连接字符串?
这对我有用:
private string ExcelConnection(string fileName)
{
return @"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data Source=" + fileName + ";" +
@"Extended Properties=" + Convert.ToChar(34).ToString() +
@"Excel 8.0" + Convert.ToChar(34).ToString() + ";";
}
我在通过 Office 365 程序从本地安装的 Office 13 升级到 Office 16 后发生了这种情况。我收到此异常:'Microsoft.ACE.OLEDB.12.0' 提供程序未在本地计算机上注册。
我找不到通过 Office 365 安装过程安装驱动程序的方法。
我不得不安装 https://www.microsoft.com/en-us/download/details.aspx?id=13255 - x64 版本没有解决问题,不得不使用 32 位版本。
我的连接字符串在 App.config
<add key="Excel07ConnectionString" value="Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR=YES'"/>
使用它的代码:
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;