First and most importantly,... Thank You Jan! EPPlus is amazing and I greatly appreciate your efforts creating and supporting it! You have simplified a difficult task for me and before anything else, I wanted to say Thank you!
I'm using EPPlus to allow some laptop users to edit a SQL database table without providing them with a direct connection to the database. They identify a set of rows which they want to change and through EPPlus, my software creates an excel workbook
and emails it to them. The workbook that is created is protected as are each of the worksheets it contains. It is an xlsm file created using an unprotected xlsm file as a template which allows it to be macro enabled with data validations and interactive
instruction displays throughout. The users are only allowed to modify the values of a few columns and they do not have the ability to add or delete worksheets, columns or in most cases, rows. On one worksheet, a macro-button is available to pop
up a dialog box through which users can safely add new rows. Over-all, the created spreadsheet provided these users with an easy and realtime-validated interface through which they can modify specific parts of rows they selected, all in a disconnected
manner. Finally, protected nature of the workbook and worksheets assures me that when the spreadsheet gets emailed back to my program, only its contents (and not its structure) will have changed. That makes parsing out the user's changes and posting
those changes to the SQL database table easy. ...and none of it would be possible without EPPlus.
So again... Thanks!
Now on to the reason for this forum entry...
Given a workbook-protected EPPlus-created xlsm file which has previously been opened by Microsoft Office Excel 2007 without a password; has received modifications to unprotected cells and been subsequently saved to disk.
The following code...
FileInfo newFile = new FileInfo(strSourceFileWithPath);
ExcelPackage package = null;
package = new ExcelPackage(newFile);
error_message += "Open Without Password Result [" + ex1.Message + "]\n";
package = new ExcelPackage(newFile, true, "Password");
error_message += "Open With Password Result [" + ex2.Message + "]\n\n";
...produces the following error_message contents...
Open Without Password Result [Can not open the package. Package is an OLE compound document. If this is an encrypted package, please supply the password]
Open With Password Result [Invalid password]
...If I then open the file again with Microsoft Office Excel 2007 and use the Unprotect WorkBook button on the Review tab to remove the workbook protection, the code above will open the spreadsheet without firing off any exceptions.
Any ideas what is causing this or what I can do avoid having to manually open each file in Excel and manually unprotect it?
Thanks in advance for any assistance!