ConnectionString用于获取Excel文件问题

在名为(ExcelFiles)的文件夹中有一个Excel文件命名(a.xlsx)。

ExcelFiles文件夹位于我的项目的根目录中。

所以我获取excel文件数据的连接字符串是这样的:

 

aaa =我的项目名称

使用此连接字符串,每个东西在本地都可以,但上传网站后我有一个错误。

问题出在哪儿??

这条路是真的 – >〜/ ExcelFiles / a.xlsx与否

你能解决这条道路吗我…

解决路径问题后,错误是这样的:

  The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine. 

我怎么能处理这个错误?

谢谢你的未来发展

最好的祝福

您托管文件的计算机没有安装ACE OleDB for office驱动程序。 我会切换到JetOleDB驱动程序

Jet OleDB连接字符串看起来像

 Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties="Excel 8.0;HDR=Yes;IMEX=1"; 

我相信Excel8.0是2003版。 对于2007年,您将需要使用Excel12.0

所以我要做的就是做一个String.Format并简单地传入excel文件的位置,当然因为这看起来像是一个asp.net应用程序所以它应该是这样的:

 String con = String.Format( @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties="Excel 8.0;HDR=Yes;IMEX=1"", Server.MapPath(EXCEL FILE LOCATION) ); 

您当然可以简单地将String.Format中使用的String放在配置文件中,这样就不像我拥有的​​那样硬编码。