When I trying open secured document I have this exception
System.Exception : Can not open the package. Package is an OLE compound document. If this is an encrypted package, please supply the password
I write this hard method for test
public bool HasPassword()
{
try
{
if(File.Exists(FileName))
{
var fileStream = File.Open(FileName, FileMode.Append);
var package = new ExcelPackage();
package.Load(fileStream);
}
}
catch(Exception)
{
return true;
}
return false;
}
but I think that it is wrong approach.
How to check whether it is password-protected excel file ?
If EEPlus isn’t mandatory you can simply use the Workbook.HasPassword property.
Therefore you need to create a reference to the Office Interop Excel component which can be found in .NET / COM (sometimes).
Then just embed it in your project with the using directive.