This file's format is not supported or you don't specify a correct format

Why do I get the following error for the code below with the attached document?


Aspose.Cells.CellsException was caught
_HResult=-2146232832
_message=This file’s format is not supported or you don’t specify a correct format.
HResult=-2146232832
IsTransient=false
Message=This file’s format is not supported or you don’t specify a correct format.
Source=Aspose.Cells
StackTrace:
at Aspose.Cells.Workbook. (String , LoadOptions )
at Aspose.Cells.Workbook…ctor(String file)
at SNL.Services.Documents.Excel.Engine.Aspose.AsposeExcelEngine.Process(String filePath, String exportFolder, String context) in c:\Projects\ContentSystems\Development\Services\SNL.Services.Documents\SNL.Services.Documents.Excel.Engine\Aspose\AsposeExcelEngine.cs:line 43
InnerException:



Code:

Workbook workbook = new Workbook(@“C:\Example.xls”);

Hi,


Thanks for providing us template file and details.

Well, your underlying template Excel file is of type e.g “Microsoft Excel 5.0/95 Workbook”. This is an older Excel file format which is not supported by Aspose.Cells, so, you are getting this exception for the file. For your information, Aspose.Cells supports BIFF8 or greater formats (Excel 97 - Excel 2010/2013, Excel 2016). To confirm this is “Microsoft Excel 5.0/95 Workbook” file, you may try to open your file into e.g MS Excel 2003/2007 and try to Save it As, now you can see the save as type something like i.e. “Microsoft Excel 5.0/95 Workbook” in the Save As dialog box.

To workaround your issue, you may try the following steps to work with the file for Aspose.Cells APIs, so that Aspose.Cells could open/process the file fine. And, I am afraid, there is no other way around.
e.g
Open your template file(s) into MS Excel (e.g…,Ms Excel 2003 or 2007).
Save the file As “Microsoft Office Excel Workbook”.
Now you can use Aspose.Cells to open/manipulate or render the files for your requirements.

Thank you.

I understand, thanks

Hi,

Thanks for your posting and using Aspose.Cells.

It is good to know that you were able to understand the root cause of this exception. Let us know if you encounter any other issue, we will be glad to look into it and help you further.

Please also see this article that will help you determine the format of your excel file on runtime.

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

Hi,
Actually i am facing this issue can you help me in overcoming in it.

So ,basically my main goal is to save a file coming from formdata to my server.So for that i am using FileUploadBean to get my file from the front end and then using Workbook to save the CSV file on my server.

FileUploadBean bean;//So this is the object which is storing the file coming from the front end
MultipartFile uploadFile= bean.getFile();

Workbook workbook = new Workbook(uploadFile.getInputStream());//the error is getting
thrown over here

@shaikabits,

In new versions (e.g Aspose.Cells v20.4.x) we also started supporting older BIFF7 (e.g “Microsoft Excel 5.0/95 Workbook” file format for certain feature. So, kindly do try latest version of the product. If you still find the issue with v20.4, kindly attach your template file, we will check it soon.

PS. please zip the file prior attaching.

fileData.zip (658 Bytes)

@cheatwole,

Thanks for the template file.

Since you are loading a CSV file from streams, so you need to specify the loadoptions for it, see the lines of code that would work fine for your needs:
e.g
Sample code:

........
TxtLoadOptions opts = new TxtLoadOptions(LoadFormat.CSV);
Workbook workbook = new Workbook(uploadFile.getInputStream(), opts);

Thanks @Amjad_Sahi now it’s not throwing that error. But, now the issue is when its creating the file in the server it’s adding this line in the file at the end(Evaluation Only. Created with Aspose.Cells for Java.Copyright 2003 - 2020 Aspose Pty Ltd.).due to which when i am reading this file its trying to read the line above it which is null.I have also shared the screenshot.Is there a way that we can avoid this line?Screenshot (57).png (112.8 KB)

@shaikabits,
It seems that your license is expired and not valid for the latest version. Please note that you can use all the versions of the products which are released before the expiry of the license. You may open the license in some text editor and check its expiry date. If the product version which you are using is released after the license expiry, then this evaluation message cannot be removed. You have to upgrade the license to use the latest versions of the product.

A post was split to a new topic: “This file’s format is not supported or you don’t specify a correct format” exception on loading the saved XLSM by Aspose.Cells