In version 2.0 (2.0-RC2) but not 1.5.1, if a cell contains an IF statement that has a message longer than 127 characters, the following error occurs: java.lang.reflect.InvocationTargetException: java.lang.IllegalArgumentException: Illegal length at org.apache.poi.util.StringUtil.getFromUnicode(StringUtil.java:170) at org.apache.poi.hssf.record.formula.StringPtg.<init> (StringPtg.java:92) at org.apache.poi.hssf.record.formula.Ptg.createPtg(Ptg.java:272) at org.apache.poi.hssf.record.FormulaRecord.getParsedExpressionTokens (FormulaRecord.java:181) at org.apache.poi.hssf.record.FormulaRecord.fillFields (FormulaRecord.java:157) at org.apache.poi.hssf.record.Record.fillFields(Record.java:127) at org.apache.poi.hssf.record.Record.<init>(Record.java:92) at org.apache.poi.hssf.record.FormulaRecord.<init> (FormulaRecord.java:122) at java.lang.reflect.Constructor.newInstance(Native Method) at org.apache.poi.hssf.record.RecordFactory.createRecord (RecordFactory.java:257) at org.apache.poi.hssf.record.RecordFactory.createRecords (RecordFactory.java:193) at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init> (HSSFWorkbook.java:207) at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init> (HSSFWorkbook.java:254) at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init> (HSSFWorkbook.java:235)
I vaguely remember there was a good reason for this limitation in POI .. I thought excel had issues with long strings in formulas in some situations.. You are trying to read an existing excel file, i presume?? Is it possible for you to attach the file to this bug? What version of Excel did u save the file with?
Created attachment 9937 [details] Sample Excel file (version Excel 2000)
With the attached Excel, the error is: java.lang.reflect.InvocationTargetException: java.lang.StringIndexOutOfBoundsException: length must be >= 0 at java.lang.String.<init>(Unknown Source) at java.lang.String.<init>(Unknown Source) at org.apache.poi.util.StringUtil.getFromCompressedUnicode (StringUtil.java:212) at org.apache.poi.hssf.record.formula.StringPtg.<init> (StringPtg.java:94) at org.apache.poi.hssf.record.formula.Ptg.createPtg(Ptg.java:272) at org.apache.poi.hssf.record.FormulaRecord.getParsedExpressionTokens (FormulaRecord.java:181) at org.apache.poi.hssf.record.FormulaRecord.fillFields (FormulaRecord.java:157) at org.apache.poi.hssf.record.Record.fillFields(Record.java:127) at org.apache.poi.hssf.record.Record.<init>(Record.java:92) at org.apache.poi.hssf.record.FormulaRecord.<init> (FormulaRecord.java:122) at java.lang.reflect.Constructor.newInstance(Native Method) at org.apache.poi.hssf.record.RecordFactory.createRecord (RecordFactory.java:257) at org.apache.poi.hssf.record.RecordFactory.createRecords (RecordFactory.java:193) at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init> (HSSFWorkbook.java:207) at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init> (HSSFWorkbook.java:254) at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init> (HSSFWorkbook.java:235)
*** Bug 26894 has been marked as a duplicate of this bug. ***
Works as of 12Jan2007, Testcase added. http://issues.apache.org/bugzilla/show_bug.cgi?id=41366