|Summary:||HSSFRichTextString.length() returns negative value if length > max|
|Product:||POI||Reporter:||Terry Paul <TerryRPaul>|
|Component:||HSSF||Assignee:||POI Developers List <dev>|
|Attachments:||Contains string that exceeds max length of Excel cell.|
Description Terry Paul 2008-12-09 08:53:55 UTC
If the length of a HSSFRichTextString object is > 32767, then a call to the length() method returns a negative value = 32767 - length. Though this isn't a big deal if it's expected behavior, it would be great to either change the method or update the Javadocs to specify this behavior.
Comment 1 Nick Burch 2008-12-09 08:56:54 UTC
Almost certainly a short vs int issue Can you please upload a file that triggers this, so we have something to hand to write a unit test against?
Comment 2 Terry Paul 2008-12-09 09:12:16 UTC
Created attachment 23006 [details] Contains string that exceeds max length of Excel cell. The attached file contains the String that when loaded into an HSSFRichTextString causes the length() method to return a negative number.
Comment 3 Terry Paul 2008-12-09 09:18:42 UTC
Uploaded an attachment containing a String longer than 32767 to assist in testing.
Comment 4 Nick Burch 2008-12-09 09:41:26 UTC
The attached file appears to be plain text, and not an excel file :( Any chance you could check your attachment, and re-upload?
Comment 5 Terry Paul 2008-12-09 10:22:58 UTC
Actually, I found the bug when I was creating an Excel file from an XML file, from which this plain text was extracted. The logic that lead to the discovery was reading the text from the XML file, creating an HSSFRichTextString object with the text, and then checking the length of that HSSFRichTextString before calling HSSFCell.setCellValue() to ensure it didn't exceed our max allowable length for a cell. Apologies for not being more clear in my original description.