Hello,
I’m migrating an application from 2.0.1 to the current Aspose.Cells version 7.0.2.
Beside of a lot of simple name changes unfortunately the behavior of the API also seem to have changed on a lot of places.
I already got a NullPointerException when I called srcCell.getR1C1Formula(), where before the method just returned null in this case.
This one seems to be an Error in the Library. Calling:
1 if (srcCell.isStyleSet())
2 {
3 final Style newStyle = new Style();
4 newStyle.copy(srcCell.getStyle());
5 newStyle.setName(srcCell.getStyle().getName());
6 dstCell.setStyle(newStyle);
7 }
Can cause a NullPointerException in line 4 which is completely unintentional. The tip of the stack trace is as follow:
Caused by: java.lang.NullPointerException
at com.aspose.cells.Font.c(Unknown Source)
at com.aspose.cells.Style.copy(Unknown Source)
BTW: The old code for this was: dstCell.setStyle((Style) srcCell.getStyle().clone())
a) Can you confirm this as a bug?
b) Are the other changes (getR1C1Formula throws a NullPointerException) by intention?
Kind Regards,
Andreas.
Hi,
Hi,
thanks for the quick response.
I downloaded 7.0.3 and still face the issue.
The Exception seems to depend on the input data. unfortunately I can not create a sample quickly. Can you get the needed Information out of the stack Trace?
java.lang.NullPointerException
at com.aspose.cells.Font.c(Unknown Source)
at com.aspose.cells.Style.copy(Unknown Source)
The exception happens while copying a number of cells. I added debug output to get information about the Font information in the style. Might be this helps?
System.out.println("New Font: " + newStyle.getFont() );
System.out.println("Old Font: " + srcCell.getStyle().getFont() );
produces:
New Font: Aspose.Cells.Font [ Arial; 10.0; Regular; com.aspose.cells.Color@ff000000 ]
Old Font: Aspose.Cells.Font [ Calibri; 11.0; Regular; com.aspose.cells.Color@ff000000 ]
in the above sample.
Kind Regards,
Andreas.
Hi,
For the issue of Style.copy(), we have found a possible bug of copying styles for a newly created Style which may cause NullPointerException and we will fix it in next fix. However, we strongly recommend users to use Workbook.createStyle() instead of new Style() to get a new Style object. And we think currently if you replace your code
final Style newStyle = new Style();
to
final Style newStyle = wb.createStyle();
your issue should be solved.
For the issue of getR1C1Formula(), we are afraid we need your template file to reproduce the issue. Please send us your template file and we will check it soon.
Thank you.
Hello,
the style copy issue is fixed when I use the wb.createStyle() way. Did I miss some documentation? I actually just wanted to replace a style.clone() which is not supported any more.
For getR1C1Formula the stack with 7.0.3 is as follows:
Caused by: java.lang.NullPointerException
at com.aspose.cells.yg.a(Unknown Source)
at com.aspose.cells.pA.a(Unknown Source)
at com.aspose.cells.op.a(Unknown Source)
at com.aspose.cells.Cell.getR1C1Formula(Unknown Source)
…
Now I use if (srcCell.isFormula() && srcCell.getR1C1Formula() != null), which works fine. I’ll try create a small sample if I find the time.
Kind Regards,
Andreas.
Hi,
From your code we know that the issue is of Cell.getR1C1Formula() for a Cell without any formula. We will make enhancement in our next fix to do with such situation and remove the exception.
Thank you.
Hi,
thanks. The the NullPointerException in getR1C1Formula is fixed with that version.
Kind Regards,
Andreas.