oledb连接string的Excel 2016在C#

我一直在尝试使用C#访问2016年MS Excel文件,但连接string工作,直到2013年MS Excel。

我目前的连接string:

Provider = Microsoft.ACE.OLEDB.12.0; Data Source = c:\ myFolder \ myExcel2007file.xlsx; Extended Properties =“Excel 12.0 Xml; HDR = YES”;

有没有修改的MS Excel 2016的oledb连接string?

从本地安装的Office 13升级到Office 16后,通过Office 365程序进行升级。 我得到这个exception:“Microsoft.ACE.OLEDB.12.0”提供程序未在本地计算机上注册。

我无法find通过Office 365安装过程安装驱动程序的方法。

我不得不安装https://www.microsoft.com/en-us/download/details.aspx?id=13255-x64版本没有解决问题,只好使用32位版本。

我在App.config中的连接string

<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; 

这对我工作:

 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() + ";"; }