You can check your file extension:
string file = @"C:\Users\Robert\Documents\Test.txt";
string extenstion = Path.GetExtension(file);
Update
I did not find any return values ββfor the situation when some file cannot be opened in the EPPlus documentation, but you can use this to catch it:
FileInfo fileInfo = new FileInfo(pathToYourFile);
ExcelPackage package = null;
try
{
package = new ExcelPackage(fileInfo);
}
catch(Exception exception)
{
...
}
catch - , .