Cannot open password protected file (Excel 2007)

Mar 28, 2013 at 10:14 AM
Edited Mar 28, 2013 at 10:14 AM
I try to open the package with password specified but the "Invalid password" exception shown up.
With the same password, I can unprotect workbook when open in Excel 2007.
Does anyone experience this problem? How can I read this protected workbook?

Below is my code snippet:
using (FileStream fileStream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
    using(var package = new ExcelPackage(fileStream, "password"))
Thank you in advance.
May 21, 2013 at 12:20 PM
I have the same issue. The unlock works in Excel 2010, but not within the Framework.

Besides, after the exception "Invalid Password" is thrown, the file remains stuck inside the process. (not sure if the framework has something to do about this.)

Did you find a solution?
May 22, 2013 at 11:40 AM
Hi BVictor,

I still found no solution to this problem.

Jun 18, 2013 at 11:22 AM
Hi again.
I did some further searching and a bit of trial and error and I got it to work. It's a strange solution though:

new ExcelPackage(filePath, "");

I had a sheet protection and a workbook protection. The password used to unlock the file in MS Office Excel was useless with EPPlus. The EEPLus protection / encryption seems to be somewhat different than the Office protection.

Keep in mind, though, that if the xlsx file is not protected, using the constructor with an empty string as password will generate an exception. You can implement a method that tries to open the file as unprotected within a try block and as protected in the catch block.