2016-05-12 145 views
1

我一直试图访问2016年MS Excel文件使用C#,但连接字符串工作,直到2013年MS Excel。oledb连接字符串为Excel 2016年在C#

我当前连接字符串:

提供商= Microsoft.ACE.OLEDB.12.0;数据源= C:\ MyFolder文件\ myExcel2007file.xlsx; 扩展属性=“Excel 12.0 Xml; HDR = YES”;

MS Excel 2016中是否有任何修改的oledb连接字符串?

回答

1

这为我工作:

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

这从本地升级通过Office 365计划到Office 16办公13的安装后发生了我。我得到这个异常:“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; 
+0

重要的是关于x64bits提。这全是我的问题。 – celerno