(Will attach test code and xls file.) When running FormulaEvaluator on a cell containing the reference formula ='Sheet 1'!A1 the Exception below is seen. A minimal test file also shows that FormulaParser.toFormulaString(...) is also missing the single quotes that exist in the formula. I was not able to identify where the single quotes were being dropped (or try to fix it) after many tries with the debugger -- I don't know the internal POI code yet. ================================ Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0 at java.lang.String.charAt(String.java:444) at org.apache.poi.hssf.util.CellReference.<init>(CellReference.java:44) at org.apache.poi.hssf.record.formula.ReferencePtg.<init>(ReferencePtg.java:50) at org.apache.poi.hssf.model.FormulaParser.Ident(FormulaParser.java:292) at org.apache.poi.hssf.model.FormulaParser.Factor(FormulaParser.java:480) at org.apache.poi.hssf.model.FormulaParser.Term(FormulaParser.java:569) at org.apache.poi.hssf.model.FormulaParser.Expression(FormulaParser.java:617) at org.apache.poi.hssf.model.FormulaParser.parse(FormulaParser.java:721) at org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.internalEvaluate(HSSFFormulaEvaluator.java:284) at org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.evaluate(HSSFFormulaEvaluator.java:181) at com.gametable.poi.Sandbox$Test.main(Sandbox.java:186) ======= Workaround: I can't think of a reasonable one, unless one has control of the spreadsheet generation.
Created attachment 16398 [details] minimal xls test file containg ref. formula with space; Excell 2002 SP1
Created attachment 16399 [details] Code that reproduces problem. In default package.
Workaround: if you just want to get the cell value, this works for many cases in 3.0-alpha1: //============= code =================== private static String tryAnything(HSSFCell cell) { try{ return cell.getNumericCellValue()+""; } catch (NumberFormatException e){ try{ return cell.getStringCellValue(); } catch (NumberFormatException f){ try{ return cell.getStringCellValue(); } catch (NumberFormatException g){ try { return cell.getDateCellValue()+""; } catch (NumberFormatException h){ // getCellBooleanValue doesn't allow fallthrough to pre-computed formula // so presumably you got a 1/0 on getNumericCellValue // earlier. return "Value not available in field."; } } } } } //=============== end of code snippet ============
Created attachment 16407 [details] Workaround code to get value of a formula cell without FormulaEvaluator Workaround in bug text was incorrect.
Problem was in Ref3DPtg which did not quote the sheet name if it contained a string/Sheetname with a space Fixed in SVN. Jason