Identifing Excel File format type

Hi,

Is there a way to find out the type of a file? eaither it is a TabDelimited or Excel97To2003 or Xlsx or csv or earlier version of 97 ? Because we will always receive single type of format as .Dat.

Hi,

I think you may use CellsHelper.DetectFileFormat() method.
e.g
MessageBox.Show(CellsHelper.DetectFileFormat(stringFilePath));
Thank you.

Hi,

The attached file is giving the FileFormat type as "Unknown". any idea why it is giving like that even though it is Tab Delimited ?

Hi,


Thank you for reporting.
We have logged an Issue in our Bug Tracking System for this. Through our initial investigation, we have verified that your provided file a Tab Delimited where as CellsHelper.DetectFileFormat method returns “Unknown” File Format Type.

The Ticket ID for your reference is CELLSNET-28655. We will soon sort this out and will let you know here.

Hi,

Thank you for this.

BTW CellsHelper.DetectFileFormat is giving Unknown for many files, I have attached one of them.

Can you save the same file as .dat format and load to a workbook like below it is throwing exception

LoadOptions loadOptions = new LoadOptions(LoadFormat.Auto);

Workbook workbook = new Workbook(FileName, loadOptions);

for the same code if I specify the LoadFormat as LoadFormat.TabDelimited then it is loading fine. I am assuming that LoadFormat.Auto will automatically detects the correct format, but somehow it is not.

One More Hard probelm we are facing is Reading of Excel 95 and earlier files. Can you suggest some component to read these files? Is it not possible for Aspose to read these files? We dont want to use Interop, Atlease if Aspose can convert the file internally and reads as a 97-2003 format is also fine

Hi,

If it is ok for you to detect older version with exception then this is a code.

C#


private void Process()
{
Workbook wb = null; //declare variable here, so that you don’t have
//to create workbook again

bool isOld= IsOldVersion(ref wb,
@“C:\Downloads\FHA_Streamline_Refinance_Worksheet_09_30_08.xls”);


if (isOld == false)
{
//save to pdf

wb.Save(@“C:\Downloads\out.pdf”);
}


}


private bool IsOldVersion(ref Workbook wb, string fileName)
{
bool isOldVersion = false;


try
{
wb = new Workbook(fileName);
}
catch (Exception ex) //You can catch specific exception or all exceptions here
{
isOldVersion = true;

wb = null;
}

return isOldVersion;
}

Note: If the file is older format, it will throw Cells.CellsException and the message will say

This Excel files contains BIFF7(Excel95 or earlier file format) records.

My problem is not only detecting old format files somehow I have to read them by saving that Old version file to Aspose supported reading fileformat automatically.

Hi,

Aspose.Cells support reading/writing Excel Oriented HTML File.

It means the html files generated by Ms-Excel. It is not possible to convert every HTML file to Excel Oriented HTML File.

We will confirm it from development team if this feature could be supported then update you.

Hi,

We have no plan to support the older MS Excel formats. In fact, we cannot support any format older than BIFF8. Aspose.Cells supports MS Excel 97 - 2010 formats.

Thanks for your understanding!