Get the error "The file's format is not supported ..." when open excel95- *.xla- *.xlam

In my application, to open excel files i use the code:


public WorkbookHelper(String excelFileName) throws Exception {
wb = new Workbook(excelFileName);
excelFilePath = excelFileName;
}

But when i test with excel95, *.xla, *.xlam i get the exception and the message: “the file’s format is not supported…” (please use the attachment data)

Does the aspose-cell not support them? Or it is my mistake?
How can i fix it?

Very stupid library:

+ I found the api to set the the file format, but i did not found the api to set the file format and file name at the sametime?
+ Why did you not implement a function which can automatically detect the file format and open it?

Hi,

Thanks for your posting and using Aspose.Cells.

Please note excel 95 and previous versions are not supported. Your Test95.xls is actually excel 95 file. Please open it in Microsoft Excel and then click Save As… and you will see Microsoft Excel will display that it is excel 95 file.

Please check the screenshot for your reference.

You can detect the format of this file dynamically using the following code. I have also shown the console output of the code.

Java

FileFormatInfo finfo = FileFormatUtil.detectFileFormat(“Test95.xls”);

//Check if the file format is excel 95
System.out.println(finfo.getFileFormatType() == FileFormatType.EXCEL_95);

Console Output
true

Please also see this related article for your reference.

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

i have two other questions:

1. when i know the file format, how can i open the workbook from filename and file format?
2. why did aspose-cell not implement the function which can open the excel file with automatically file format detection?

Hi,

Thanks for your posting and using Aspose.Cells.

1. when i know the file format, how can i open the workbook from filename and file format?

Workbook constructor takes a parameter LoadOptions, you can create LoadOptions from the FileFormatInfo using the following code.

LoadOptions opts = new LoadOptions(finfo.getLoadFormat());

The following sample code detects the file format of file, then creates loadoptions object and finally creates workbook object.

Java
String[] filenames = { “HuongExcelAddIn97-2004_NOK.xla”, “HuongExcelMacro_NOK.xlsm”, “HuongExcelAddIn_NOK.xlam”, “Test95.xls” };

for(int i=0; i<filenames.length; i++)
{
System.out.println(filenames[i]);

FileFormatInfo finfo = FileFormatUtil.detectFileFormat(filenames[i]);

LoadOptions opts = new LoadOptions(finfo.getLoadFormat());

Workbook wb = new Workbook(filenames[i], opts);
}

2. why did aspose-cell not implement the function which can open the excel file with automatically file format detection?

Aspose.Cells is able to detect file formats via file extensions. The following code loads your files into workbook object by names and it works fine except it throws exception for Excel 95 file.

Java
String[] filenames = { “HuongExcelAddIn97-2004_NOK.xla”, “HuongExcelMacro_NOK.xlsm”, “HuongExcelAddIn_NOK.xlam”, “Test95.xls” };

for(int i=0; i<filenames.length; i++)
{
System.out.println(filenames[i]);

Workbook wb = new Workbook(filenames[i]);
}