使用OleDB从受密码保护的Excel文件中获取数据

问题描述:

我正在使用此连接字符串访问excel(2007,2010)文件

I'm using this connection string to access excel(2007,2010) files

oleConnection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filepath + ";Extended Properties='Excel 12.0;HDR = NO;IMEX = 1;'";

这项工作正常,直到我尝试从受保护列表中获取数据. 我知道保护密码. 那么我该如何访问受保护列表?

this work fine until i try to get data from protected List. I know the protection password. So how could i access protected list?

按照 MSDN ,您可以为凭据提供连接字符串User ID=UserX;Password=UserXPassword,但这可用于访问

As per MSDN you can provide the credentials with the connection string User ID=UserX;Password=UserXPassword but this works for access

但是

恐怕.您无法打开与受密码保护的连接 电子表格,除非您已经在中手动打开了电子表格 Excel.所描述的错误与 Excel ODBC提供程序,但在Jet 4.0 OLE中的行为是相同的 数据库提供者.您的另一个选择是从 电子表格,并依靠其他一些安全机制(例如 限制文件所在文件夹的权限) 控制访问权限.

I'm afraid. You cannot open a connection to a password-protected spreadsheet unless you have already manually opened the spreadsheet in Excel . The described error is with the Excel ODBC provider, but the behavior is identical in the Jet 4.0 OLE DB provider. Your other option is to remove the password from the spreadsheet, and rely on some other security mechanism (like restricting permissions on the folder where the file resides) to control access.