简体   繁体   中英

Check for password protected file with EPPlus ExcelPackage

What is the correct way to check is an excel file is password protected (I do not know the password)? When I try to open it I get a non-specific exception ("A disk error occurred during a write operation.") that could be related to any other type of invalid file. Thanks

If I try to open a password protected xlsx file, I get the exception -

{"Can not open the package. Package is an OLE compound document. If this is an encrypted package, please supply the password"}

It also suggests using the overloaded method to open it

sample:

string mySpreadsheetName = @"path/to/file/name/xlsx";
FileInfo fi = new FileInfo(mySpreadsheetName);
ExcelPackage p1 = new ExcelPackage(fi, "abcd"); // this opens correctly, here "abcd" is the password
ExcelPackage p2 = new ExcelPackage(fi); //this throws an exception

Are you getting a different exception ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM