I'm trying to determine the best way to open a protected worksheet, if even possible. I've done a little research in spreadsheetgear's documentation and I haven't really been able to track down a solution yet.
I've come across two options that I think might be able to help. Spreadsheetgear does have an Unprotect(string password)
method but as of right now I cant get it to work. I have the user select a workbook on their local system and upload it to the server. When I try to open and read the file, the page breaks and throws an exception
Corrupt OpenXML document.
As of right now I open unprotected workbooks like so
byte[] file = Session["FileUpload"] as byte[];
using (MemoryStream fileStream = new MemoryStream(file))
{
IWorkbook workbook = Factory.GetWorkbookSet().Workbooks.OpenFromStream(fileStream);
.....
}
This works fine on an unprotected workbook but when its protected I get the corrupt document error. Ideally, I would want to unprotect and open at the same time but I'm not sure how to accomplish this.OpenFromStream
does have an overload where you can feed it a string as a password which I tried but no luck there. The documentation isn't great for these methods so I'm not sure if I was even using them correctly.