Search code examples
asp.netexceloledb

How to read data from a password-protected Excel worksheet


I've been looking for an answer for that problem, I just can't read my password-protected Excel file, but when I try with a copy of that file (without password) it works, this is my connection string, I'm using OleDB

var excelConn = "provider=Microsoft.ACE.OLEDB.12.0;data source=" + excelFilePath + ";Extended Properties='Excel 12.0 Xml;HDR=YES;user id=;password=P-ICS'";

My OleDbCommand:

oleDbCommand.CommandText = "INSERT INTO [MS Access;database=" + accessFilePath + "].[temp]"+
                           "SELECT [Create],[Lote],[Qtd],[F10],[Término Real],[Número da Ordem]" +
                           "FROM [R 1120$]";

That's all, sorry about my English, thanks.


Solution

  • If the Excel workbook is protected by a password, you cannot open it for data access, even by supplying the correct password with your connection string.

    http://support.microsoft.com/kb/257819