Excel File Version

If I just want to validate the Excel file version information, how would you recommend doing it with Aspose.Cells?

I ask because the exception it throws when attempting to open a BIFF5 format file is the same as the one it throws when, for example, opening a text file with an XLS extension or some other "non-Excel" file--"This file's format is not supported or you don't specify a correct format".

I know Aspose.Cells does not support BIFF5 format files. I do not want full support for them--just a specific Exception for them.

I need to tell the difference between a corrupt Excel file, a BIFF5 file, and a file that is not an Excel file at all that simply has an XLS or XLSX extension.

Thanks.

Ray

Hi,

Thanks for your posting and considering Aspose.Cells.

FileFormatUtil.DetectFileFormat() method should fit your needs. Please check the attached abc.txt file. It is actually an xlsb file. If you change its extension to xlsb, it will open up in Microsoft Excel.

Please see the following code and its console output. The code successfully detects the actual format of abc.txt file.

Please also see the following documentation article for your reference.

( How to Detect a File Format and Check if the File is Encrypted|Documentation )

C#

// abc.txt is actually an xlsb file

//Detect file format
FileFormatInfo info = FileFormatUtil.DetectFileFormat(“abc.txt”);

//Gets the detected load format
Console.WriteLine("The spreadsheet format is: " + FileFormatUtil.LoadFormatToExtension(info.LoadFormat));

//Check if the file is encrypted.
Console.WriteLine("The file is encrypted: " + info.IsEncrypted);

Console Output:
The spreadsheet format is: .xlsb
The file is encrypted: False