https://issues.apache.org/bugzilla/show_bug.cgi?id=48526

--- Comment #3 from Brendan Nolan <[email protected]> 2010-08-10 18:36:17 
EDT ---
Created an attachment (id=25876)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=25876)
Adds support for RANDBETWEEN() function. The zip file contains a svn diff and a
tar file which contains an Excel spreadsheet for testing

RANDBETWEEN is one of the Analysis Toolpak formula and I have implemented it as
such rather than an entry in NumericFunctions

One strange behavior I noticed while formulating Testcases for the function was
that it can't be assigned into a workbook created directly in POI. The same is
true for all the currently implemented ATP functions ISEVEN(), ISODD() and
YEARFRAC()

If you run the following

Workbook wb = new HSSFWorkbook();    
Sheet sheet = wb.createSheet("ATPSheet");
Row row = sheet.createRow(0);
Cell formulaCell = row.createCell(0, HSSFCell.CELL_TYPE_FORMULA);
formulaCell.setCellFormula("ISEVEN()");

You will get the following exception:

Exception in thread "main" org.apache.poi.ss.formula.FormulaParseException:
Name 'ISEVEN' is completely unknown in the current workbook
    at org.apache.poi.ss.formula.FormulaParser.function(FormulaParser.java:914)
    at
org.apache.poi.ss.formula.FormulaParser.parseNonRange(FormulaParser.java:552)
    at
org.apache.poi.ss.formula.FormulaParser.parseRangeable(FormulaParser.java:423)
    at
org.apache.poi.ss.formula.FormulaParser.parseRangeExpression(FormulaParser.java:266)
    at
org.apache.poi.ss.formula.FormulaParser.parseSimpleFactor(FormulaParser.java:1113)
    at
org.apache.poi.ss.formula.FormulaParser.percentFactor(FormulaParser.java:1073)
    at
org.apache.poi.ss.formula.FormulaParser.powerFactor(FormulaParser.java:1060)
    at org.apache.poi.ss.formula.FormulaParser.Term(FormulaParser.java:1420)
    at
org.apache.poi.ss.formula.FormulaParser.additiveExpression(FormulaParser.java:1520)
    at
org.apache.poi.ss.formula.FormulaParser.concatExpression(FormulaParser.java:1504)
    at
org.apache.poi.ss.formula.FormulaParser.comparisonExpression(FormulaParser.java:1461)
    at
org.apache.poi.ss.formula.FormulaParser.unionExpression(FormulaParser.java:1441)
    at org.apache.poi.ss.formula.FormulaParser.parse(FormulaParser.java:1562)
    at org.apache.poi.ss.formula.FormulaParser.parse(FormulaParser.java:174)
    at
org.apache.poi.hssf.model.HSSFFormulaParser.parse(HSSFFormulaParser.java:72)
    at org.apache.poi.hssf.usermodel.HSSFCell.setCellFormula(HSSFCell.java:598)

If you open a Workbook that has the ATP formula already present they you are
able to assign the formula to new cells without issue.

Is this expected behavior or is there a defect with the ATP functions? Or do
you need to alter the workbook after creation to support the ATP functions?

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to