保護されたドキュメントを開こうとすると、この例外が発生します
System.Exception : Can not open the package. Package is an OLE compound document. If this is an encrypted package, please supply the password
テスト用にこの難しいメソッドを書きます
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;
}
しかし、それは間違ったアプローチだと思います。
パスワードで保護されたExcelファイルかどうかを確認する方法は?