NullPointerException opening Excel Spreadsheet

I’m getting a NullPointerException trying to open a spreadsheet. Here’s the stacktrace:


java.lang.NullPointerException
at com.aspose.cells.zi.b(Unknown Source)
at com.aspose.cells.zi.a(Unknown Source)
at com.aspose.cells.aad.k(Unknown Source)
at com.aspose.cells.aad.a(Unknown Source)
at com.aspose.cells.aac.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.(Unknown Source)

LibreOffice has no problem opening this file, but Google Sheets refuses to open it. File attached.

Thanks,
Roy

Hi,


I have tested your scenario/case with latest Aspose.Cells version v7.5.3( JAVA). Well, your file contains records/data of Excel 4.0 or earlier versions, so you cannot open/read the file by Aspose.Cells APIs. If you could open your XLS files into MS Excel (MS Excel 2003) manually and click on the SaveAs, you will see what type of this file actually is. I am afraid, Aspose.Cells does not support to read/write BIFF7 or older file formats as it only supports BIFF8 and greater file formats (Excel 97 - Excel 2010), so you are getting this exception. We can only suggest a workaround for you as we cannot support the older file formats in our product. You may try the following steps to work with these files 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).
Save the file As “Microsoft Office Excel Workbook”.
Now you can use Aspose.Cells to open/manipulate, render or convert the file for your requirements, it will work fine as I tested following the above steps too.

Thank you.

Hello,


This is not a one-off file - I’m packaging Aspose Cells in my product and it is used to process arbitrary Excel files supplied by my customers. It’s fine if the answer is this file’s format is too old and not supported, but I need to have an exception with a better error message that my product can show my customers.

For some other files I’ve tried you throw an exception with message “This Excel files contains BIFF7(Excel 95 or earlier format) records”. Something like that would be good. A NullPointerException with no message is not acceptable.

Thanks,
Roy

Hi,


Well, I used Aspose.Cells for Java v7.5.3 (latest version) and I got the following exception:

"Exception in thread “main” com.aspose.cells.CellsException: This Excel files contains (Excel4.0 or earlier file format) records."

I think it (exception message) is fine.

Thank you.

I upgraded to Cells for Java 7.5.3 (I was on 7.5.2) but I still get the NullPointerException. I’m calling new Workbook(InputStream) with the contents of the attached file, and it’s throwing an NPE with no message.


Thanks,
Roy

Hi,


Well, that is strange, it might be due to your code. Could you share your sample runnable code here to reproduce the issue on our end, we will check it soon.

By the way, I am using the following sample code with your template file, I got the error message as I pasted in my previous post:

E.g

Sample code:
Workbook workbook = new Workbook(“lboval.xls”);

Thank you.

I see the problem. If you call the Workbook constructor that takes a String then you get a CellsException with a nice error message, but if you call the constructor that takes an InputStream you get the NullPointerException with no error message:


String fileName = “lboval.xls”;

try {
//correctly throws CellsException with good message
new Workbook(fileName);
} catch (CellsException e) {
//expected
assert e.getMessage().contains(“This Excel files contains (Excel4.0 or earlier file format) records.”);
}

try {
InputStream stream = new FileInputStream(fileName);
//Incorrectly throws NullPointerException with no message
new Workbook(stream);
} catch (Throwable tbl) {
tbl.printStackTrace();
}



Hi,


I have evaluated your issue and found the issue as you have mentioned. If we call the constructor that takes an InputStream we only get the NullPointerException without proper description/error message. I have logged a ticket with an id “CELLSJAVA-40615” for your issue. We will look into it to figure it out soon.

Thank you.

Hi,

Please try our latest version/fix: Aspose.Cells for Java v7.5.3.2 (attached). Now we give the same exception Code: ExceptionType.UNSUPPORTED_FEATURE, Message: This Excel files contains (Excel4.0 or earlier file format) records.) when reading the unsupported template file by filename or stream.

Thank you.

Hello,


I tried it and I can confirm that 7.5.3.2 fixes this problem.

Thanks!
Roy

Hi,


Good to know that your issue is resolved by the new fix. We have closed your ticket now.

Feel free to contact us anytime if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.

The issues you have found earlier (filed as CELLSJAVA-40615) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.