Problem converting xls file to pdf: "This file's format is not supported or you don't specify a correct format"

Hi,


I got the following exception, while trying to convert xls to pdf:
“This file’s format is not supported or you don’t specify a correct format”.

attached is the problematic file.

I am using the latest version.

Is this Aspose bug ?

thanks,
Eran.

Hi Eran,

Thanks for your posting and using Aspose.Cells.

This file is actually in a very old format which is not supported by Aspose.Cells. If you open it in MS-Excel and save it with Save As menu command, you will see MS-Excel will show you its format i.e

Microsoft Excel 5.0/95 Workbook (*.xls)

So this file is actually in a Microsoft Excel 5.0 or 95 format which is not supported by Aspose.Cells.

I have attached the screenshot for your reference.

You can also use this code to detect the FileFormatType of this file.

Java


FileFormatInfo finfo = FileFormatUtil.detectFileFormat(“Budget_Report_2014-2015_10_31_14_YTD_Compressed+copy.xls”);


System.out.println(finfo.getFileFormatType()== FileFormatType.EXCEL_95);

Console Output:
true

Furthermore, FYI, Aspose.Cells supports BIFF8 or greater formats (Excel 97 - Excel 2010/2013), so you cannot read/write the Excel 95 or earlier file formats.

As a workaround, you may try the following steps to work with the file for Aspose.Cells product, so that Aspose.Cells could open/process the file fine, there is no alternative I am afraid:
e.g
Open your template file into MS Excel (e.g..,Ms Excel 2003 or 2007/2010).
Save the file As "Microsoft Office Excel Workbook".

Now you can use Aspose.Cells to open/manipulate the file for your requirements, it will work fine.

thanks for your reply.


is there a way to give the function an array of bytes ?


Hi Eran,


Could you please elaborate, to which function do you wish to pass an array of bytes? In case you are talking about the Workbook constructor then please note, you can either pass the file path location in string or an instance of InputStream so you can convert the array of bytes to InputStream and pass it to Workbook constructor. If your scenario is different then please provide more details.

FileFormatUtil.detectFileFormat(byteArr)


while byteArr are byte[] of a file.

We want to check it on Runtime, we dont have a file,
and we have already read all the bytes from the InputStream.

Hi Eran,


Thank you for the elaboration.

I am afraid, the FileFormatUtil.detectFileFormat method also requires either the InputStream or the file path location in order to detect the file’s format. In case you have the InputStream then you can pass it to the aforesaid method before converting it to byte array otherwise you have to do the conversion again.
eran4:
FileFormatUtil.detectFileFormat(byteArr)

while byteArr are byte[] of a file.

We want to check it on Runtime, we dont have a file,
and we have already read all the bytes from the InputStream.


Hi,

Thanks for your posting and using Aspose.Cells.

Now that you have the binary array of the file data, it is easy for you to build an InputStream from the byte[].

Please see the following code for your reference.

Java
ByteArrayInputStream is = new ByteArrayInputStream(byteArr);

FileFormatUtil.detectFileFormat(is);