--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.AddPtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ * This is a documentation of the observed behaviour of
+ * the '+' operator in Excel:
+ * <ol>
+ * <li> 1+TRUE = 2
+ * <li> 1+FALSE = 1
+ * <li> 1+"true" = #VALUE!
+ * <li> 1+"1" = 2
+ * <li> 1+A1 = #VALUE if A1 contains "1"
+ * <li> 1+A1 = 2 if A1 contains ="1"
+ * <li> 1+A1 = 2 if A1 contains TRUE or =TRUE
+ * <li> 1+A1 = #VALUE! if A1 contains "TRUE" or ="TRUE"
+ */
+public class AddEval extends NumericOperationEval {
+
+ private AddPtg delegate;
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ public AddEval(Ptg ptg) {
+ delegate = (AddPtg) ptg;
+ }
+
+ public ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ Eval retval = null;
+ double d = 0;
+ switch (operands.length) {
+ default: // will rarely happen. currently the parser itself fails.
+ retval = ErrorEval.UNKNOWN_ERROR;
+ break;
+ case 2:
+ for (int i = 0, iSize = 2; retval==null && i < iSize; i++) {
+ ValueEval ve = singleOperandEvaluate(operands[i], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ d += ((NumericValueEval) ve).getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ } // end for inside case
+ } // end switch
+
+ if (retval == null) {
+ retval = Double.isNaN(d) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+
+ return retval;
+ }
+
+ public int getNumberOfOperands() {
+ return delegate.getNumberOfOperands();
+ }
+
+ public int getType() {
+ return delegate.getType();
+ }
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.AreaPtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Area2DEval implements AreaEval {
+
+ private AreaPtg delegate;
+
+ private ValueEval[] values;
+
+ public Area2DEval(Ptg ptg, ValueEval[] values) {
+ this.delegate = (AreaPtg) ptg;
+ this.values = values;
+ }
+
+ public short getFirstColumn() {
+ return delegate.getFirstColumn();
+ }
+
+ public int getFirstRow() {
+ return delegate.getFirstRow();
+ }
+
+ public short getLastColumn() {
+ return delegate.getLastColumn();
+ }
+
+ public int getLastRow() {
+ return delegate.getLastRow();
+ }
+
+ public ValueEval[] getValues() {
+ return values;
+ }
+
+ public ValueEval getValueAt(int row, short col) {
+ ValueEval retval;
+ int index = ((row-getFirstRow())*(getLastColumn()-getFirstColumn()+1))+(col-getFirstColumn());
+ if (index <0 || index >= values.length)
+ retval = ErrorEval.VALUE_INVALID;
+ else
+ retval = values[index];
+ return retval;
+ }
+
+ public boolean contains(int row, short col) {
+ return (getFirstRow() <= row) && (getLastRow() >= row)
+ && (getFirstColumn() <= col) && (getLastColumn() >= col);
+ }
+
+ public boolean containsRow(int row) {
+ return (getFirstRow() <= row) && (getLastRow() >= row);
+ }
+
+ public boolean containsColumn(short col) {
+ return (getFirstColumn() <= col) && (getLastColumn() >= col);
+ }
+
+ public boolean isColumn() {
+ return delegate.getFirstColumn() == delegate.getLastColumn();
+ }
+
+ public boolean isRow() {
+ return delegate.getFirstRow() == delegate.getLastRow();
+ }
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.Area3DPtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Area3DEval implements AreaEval {
+
+ private Area3DPtg delegate;
+
+ private ValueEval[] values;
+
+ public Area3DEval(Ptg ptg, ValueEval[] values) {
+ this.values = values;
+ this.delegate = (Area3DPtg) ptg;
+ }
+
+ public short getFirstColumn() {
+ return delegate.getFirstColumn();
+ }
+
+ public int getFirstRow() {
+ return delegate.getFirstRow();
+ }
+
+ public short getLastColumn() {
+ return delegate.getLastColumn();
+ }
+
+ public int getLastRow() {
+ return delegate.getLastRow();
+ }
+
+ public ValueEval[] getValues() {
+ return values;
+ }
+
+ public ValueEval getValueAt(int row, short col) {
+ ValueEval retval;
+ int index = (row-getFirstRow())*(col-getFirstColumn());
+ if (index <0 || index >= values.length)
+ retval = ErrorEval.VALUE_INVALID;
+ else
+ retval = values[index];
+ return retval;
+ }
+
+ public boolean contains(int row, short col) {
+ return (getFirstRow() <= row) && (getLastRow() >= row)
+ && (getFirstColumn() <= col) && (getLastColumn() >= col);
+ }
+
+ public boolean containsRow(int row) {
+ return (getFirstRow() <= row) && (getLastRow() >= row);
+ }
+
+ public boolean containsColumn(short col) {
+ return (getFirstColumn() <= col) && (getLastColumn() >= col);
+ }
+
+
+ public boolean isColumn() {
+ return delegate.getFirstColumn() == delegate.getLastColumn();
+ }
+
+ public boolean isRow() {
+ return delegate.getFirstRow() == delegate.getLastRow();
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public interface AreaEval extends ValueEval {
+
+ /**
+ * returns the 0-based index of the first row in
+ * this area.
+ * @return
+ */
+ public int getFirstRow();
+
+ /**
+ * returns the 0-based index of the last row in
+ * this area.
+ * @return
+ */
+ public int getLastRow();
+
+ /**
+ * returns the 0-based index of the first col in
+ * this area.
+ * @return
+ */
+ public short getFirstColumn();
+
+ /**
+ * returns the 0-based index of the last col in
+ * this area.
+ * @return
+ */
+ public short getLastColumn();
+
+ /**
+ * returns true if the Area's start and end row indexes
+ * are same. This result of this method should agree
+ * with getFirstRow() == getLastRow().
+ * @return
+ */
+ public boolean isRow();
+
+ /**
+ * returns true if the Area's start and end col indexes
+ * are same. This result of this method should agree
+ * with getFirstColumn() == getLastColumn().
+ * @return
+ */
+ public boolean isColumn();
+
+ /**
+ * The array of values in this area. Although the area
+ * maybe 1D (ie. isRow() or isColumn() returns true) or 2D
+ * the returned array is 1D.
+ * @return
+ */
+ public ValueEval[] getValues();
+
+ /**
+ * returns the ValueEval from the values array at the specified
+ * row and col index. The specified indexes should be absolute indexes
+ * in the sheet and not relative indexes within the area. Also,
+ * if contains(row, col) evaluates to true, a null value will
+ * bre returned.
+ * @param row
+ * @param col
+ * @return
+ */
+ public ValueEval getValueAt(int row, short col);
+
+ /**
+ * returns true if the cell at row and col specified
+ * as absolute indexes in the sheet is contained in
+ * this area.
+ * @param row
+ * @param col
+ * @return
+ */
+ public boolean contains(int row, short col);
+
+ /**
+ * returns true if the specified col is in range
+ * @param col
+ * @return
+ */
+ public boolean containsColumn(short col);
+
+ /**
+ * returns true if the specified row is in range
+ * @param row
+ * @return
+ */
+ public boolean containsRow(int row);
+}
--- /dev/null
+/*
+ * Created on May 9, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com > This class is a
+ * marker class. It is a special value for empty cells.
+ */
+public class BlankEval implements ValueEval {
+
+ public static BlankEval INSTANCE = new BlankEval();
+
+ private BlankEval() {
+ }
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.BoolPtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class BoolEval implements NumericValueEval, StringValueEval {
+
+ private boolean value;
+
+ public static final BoolEval FALSE = new BoolEval(false);
+
+ public static final BoolEval TRUE = new BoolEval(true);
+
+ public BoolEval(Ptg ptg) {
+ this.value = ((BoolPtg) ptg).getValue();
+ }
+
+ private BoolEval(boolean value) {
+ this.value = value;
+ }
+
+ public boolean getBooleanValue() {
+ return value;
+ }
+
+ public double getNumberValue() {
+ return value ? (short) 1 : (short) 0;
+ }
+
+ public String getStringValue() {
+ return value ? "TRUE" : "FALSE";
+ }
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.ConcatPtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class ConcatEval extends StringOperationEval {
+
+ private ConcatPtg delegate;
+
+ public ConcatEval(Ptg ptg) {
+ this.delegate = (ConcatPtg) ptg;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ Eval retval = null;
+ StringBuffer sb = null;
+
+ switch (operands.length) {
+ default: // paranoid check :)
+ retval = ErrorEval.UNKNOWN_ERROR;
+ break;
+ case 2:
+ sb = new StringBuffer();
+ for (int i = 0, iSize = 2; retval == null && i < iSize; i++) {
+
+ ValueEval ve = singleOperandEvaluate(operands[i], srcRow, srcCol);
+ if (ve instanceof StringValueEval) {
+ StringValueEval sve = (StringValueEval) ve;
+ sb.append(sve.getStringValue());
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else { // must be an error eval
+ retval = ve;
+ }
+ }
+ }
+
+ if (retval == null) {
+ retval = new StringEval(sb.toString());
+ }
+ return retval;
+ }
+
+ public int getNumberOfOperands() {
+ return delegate.getNumberOfOperands();
+ }
+
+ public int getType() {
+ return delegate.getType();
+ }
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.record.formula.DividePtg;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class DivideEval extends NumericOperationEval {
+
+ private DividePtg delegate;
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ public DivideEval(Ptg ptg) {
+ delegate = (DividePtg) ptg;
+ }
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ Eval retval = null;
+ double d0 = 0;
+ double d1 = 0;
+ switch (operands.length) {
+ default: // will rarely happen. currently the parser itself fails.
+ retval = ErrorEval.UNKNOWN_ERROR;
+ break;
+ case 2:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ d0 = ((NumericValueEval) ve).getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+
+ if (retval == null) { // no error yet
+ ve = singleOperandEvaluate(operands[1], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ d1 = ((NumericValueEval) ve).getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
+ } // end switch
+
+ if (retval == null) {
+ retval = (d1 == 0)
+ ? ErrorEval.DIV_ZERO
+ : (Double.isNaN(d0) || Double.isNaN(d1))
+ ? (ValueEval) ErrorEval.VALUE_INVALID
+ : new NumberEval(d0 / d1);
+ }
+ return retval;
+ }
+
+ public int getNumberOfOperands() {
+ return delegate.getNumberOfOperands();
+ }
+
+ public int getType() {
+ return delegate.getType();
+ }
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.EqualPtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class EqualEval extends RelationalOperationEval {
+
+ private EqualPtg delegate;
+
+ public EqualEval(Ptg ptg) {
+ this.delegate = (EqualPtg) ptg;
+ }
+
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ ValueEval retval = null;
+
+ RelationalValues rvs = super.doEvaluate(operands, srcRow, srcCol);
+ retval = rvs.ee;
+ int result = 0;
+ if (retval == null) {
+ result = doComparison(rvs.bs);
+ if (result == 0) {
+ result = doComparison(rvs.ss);
+ }
+ if (result == 0) {
+ result = doComparison(rvs.ds);
+ }
+
+ retval = (result == 0) ? BoolEval.TRUE : BoolEval.FALSE;
+ }
+
+ return retval;
+ }
+
+ public int getNumberOfOperands() {
+ return delegate.getNumberOfOperands();
+ }
+
+ public int getType() {
+ return delegate.getType();
+ }
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ * Error code reference from OpenOffice documentation: <br/><TABLE WIDTH=575
+ * BORDER=1 CELLPADDING=2 CELLSPACING=0 BGCOLOR="#ffffff"> <COL WIDTH=42> <COL
+ * WIDTH=118> <COL WIDTH=401>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="tablehead" ALIGN=LEFT>
+ * Error Code
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="tablehead" ALIGN=LEFT>
+ * Message
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="tablehead" ALIGN=LEFT>
+ * Explanation
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 501
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Invalid character
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Character in a formula is not valid, for example, "=1Eq" instead of
+ * "=1E2".
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 502
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Invalid argument
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Function argument is not valid, for example, a negative number for the root
+ * function.
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 503
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Invalid floating point operation
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Division by 0, or another calculation that results in an overflow of the
+ * defined value range.
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 504
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Parameter list error
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Function parameter is not valid, for example, text instead of a number, or a
+ * domain reference instead of cell reference.
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 505
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Internal syntax error
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Not used
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 506
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Invalid semicolon
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Not used
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 507
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Error: Pair missing
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Not used
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 508
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Error: Pair missing
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Missing bracket, for example, closing brackets, but no opening brackets
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 509
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Missing operator
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Operator is missing, for example, "=2(3+4) * ", where the operator
+ * between "2" and "(" is missing.
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 510
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Missing variable
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Variable is missing, for example when two operators are together
+ * "=1+*2".
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 511
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Missing variable
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Function requires more variables than are provided, for example, AND() and
+ * OR().
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 512
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Formula overflow
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * <B>Compiler: </B> the total number of internal tokens, (that is, operators,
+ * variables, brackets) in the formula exceeds 512. <B>Interpreter: </B> the
+ * total number of matrices that the formula creates exceeds 150. This includes
+ * basic functions that receive too large an array as a parameter (max. 0xFFFE,
+ * for example, 65534 bytes).
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 513
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * String overflow
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * <B>Compiler: </B> an identifier in the formula exceeds 64 KB in size.
+ * <B>Interpreter: </B> a result of a string operation exceeds 64 KB in size.
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 514
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Internal overflow
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Sort operation attempted on too much numerical data (max. 100000) or a
+ * calculation stack overflow.
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 515
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Internal syntax error
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Not used
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 516
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Internal syntax error
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Matrix is expected on the calculation stack, but is not available.
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 517
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Internal syntax error
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Unknown code, for example, a document with a newer function is loaded in an
+ * older version that does not contain the function.
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 518
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Internal syntax error
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Variable is not available
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 519
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * No result (#VALUE is in the cell rather than Err:519!)
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Formula yields a value that does not corresponds to the definition, or a cell
+ * that is referenced in the formula contains text instead of a number.
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 520
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Internal syntax error
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Compiler creates an unknown compiler code.
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 521
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Internal syntax error
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * No result.
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 522
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Circular reference
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Formula refers directly or indirectly to itself and the iterations option is
+ * not selected under Tools - Options - Table Document - Calculate.
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 523
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * The calculation procedure does not converge
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Financial statistics function missed a targeted value or iterations of
+ * circular references do not reach the minimum change within the maximum steps
+ * that are set.
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 524
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * <A NAME="kw66944_5"> </A><A NAME="kw66944_4"> </A> invalid references
+ * (instead of Err:524 cell contains #REF)
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * <B>Compiler: </B> a column or row description name could not be resolved.
+ * <B>Interpreter: </B> in a formula, the column, row, or sheet that contains a
+ * referenced cell is missing.
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 525
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * <A NAME="kw66944_3"> </A><A NAME="kw66944_2"> </A> invalid names (instead of
+ * Err:525 cell contains #NAME?)
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * An identifier could not be evaluated, for example, no valid reference, no
+ * valid domain name, no column/row label, no macro, incorrect decimal divider,
+ * add-in not found.
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 526
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Internal syntax error
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Obsolete, no longer used, but could come from old documents if the result is
+ * a formula from a domain.
+ * </P>
+ * </TD>
+ * </TR>
+ * <TR VALIGN=TOP>
+ * <TD WIDTH=42 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * 527
+ * </P>
+ * </TD>
+ * <TD WIDTH=118 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * Internal overflow
+ * </P>
+ * </TD>
+ * <TD WIDTH=401 BGCOLOR="#ffffff">
+ * <P CLASS="textintable" ALIGN=LEFT>
+ * <B>Interpreter: </B>References, such as when a cell references a cell, are
+ * too encapsulated.
+ * </P>
+ * </TD>
+ * </TR>
+ * </TABLE>
+ *
+ */
+public class ErrorEval implements ValueEval {
+
+ private int errorCode;
+
+ // Oo std error codes
+ public static final ErrorEval ERROR_501 = new ErrorEval(501);
+
+ public static final ErrorEval ERROR_502 = new ErrorEval(502);
+
+ public static final ErrorEval ERROR_503 = new ErrorEval(503);
+
+ public static final ErrorEval ERROR_504 = new ErrorEval(504);
+
+ public static final ErrorEval ERROR_505 = new ErrorEval(505);
+
+ public static final ErrorEval ERROR_506 = new ErrorEval(506);
+
+ public static final ErrorEval ERROR_507 = new ErrorEval(507);
+
+ public static final ErrorEval ERROR_508 = new ErrorEval(508);
+
+ public static final ErrorEval ERROR_509 = new ErrorEval(509);
+
+ public static final ErrorEval ERROR_510 = new ErrorEval(510);
+
+ public static final ErrorEval ERROR_511 = new ErrorEval(511);
+
+ public static final ErrorEval ERROR_512 = new ErrorEval(512);
+
+ public static final ErrorEval ERROR_513 = new ErrorEval(513);
+
+ public static final ErrorEval ERROR_514 = new ErrorEval(514);
+
+ public static final ErrorEval ERROR_515 = new ErrorEval(515);
+
+ public static final ErrorEval ERROR_516 = new ErrorEval(516);
+
+ public static final ErrorEval ERROR_517 = new ErrorEval(517);
+
+ public static final ErrorEval ERROR_518 = new ErrorEval(518);
+
+ public static final ErrorEval ERROR_519 = new ErrorEval(519);
+
+ public static final ErrorEval ERROR_520 = new ErrorEval(520);
+
+ public static final ErrorEval ERROR_521 = new ErrorEval(521);
+
+ public static final ErrorEval ERROR_522 = new ErrorEval(522);
+
+ public static final ErrorEval ERROR_523 = new ErrorEval(523);
+
+ public static final ErrorEval ERROR_524 = new ErrorEval(524);
+
+ public static final ErrorEval ERROR_525 = new ErrorEval(525);
+
+ public static final ErrorEval ERROR_526 = new ErrorEval(526);
+
+ public static final ErrorEval ERROR_527 = new ErrorEval(527);
+
+ public static final ErrorEval NAME_INVALID = ERROR_525;
+
+ public static final ErrorEval VALUE_INVALID = ERROR_519;
+
+
+ // Non std error codes
+ public static final ErrorEval UNKNOWN_ERROR = new ErrorEval(-20);
+
+ public static final ErrorEval FUNCTION_NOT_IMPLEMENTED = new ErrorEval(-30);
+
+ public static final ErrorEval REF_INVALID = new ErrorEval(-40);
+
+ public static final ErrorEval NA = new ErrorEval(-50);
+
+ public static final ErrorEval CIRCULAR_REF_ERROR = new ErrorEval(-60);
+
+ public static final ErrorEval DIV_ZERO = new ErrorEval(-70);
+
+ public static final ErrorEval NUM_ERROR = new ErrorEval(-80);
+
+ private ErrorEval(int errorCode) {
+ this.errorCode = errorCode;
+ }
+
+ public int getErrorCode() {
+ return errorCode;
+ }
+
+ public String getStringValue() {
+ return "Err:" + Integer.toString(errorCode);
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public interface Eval {
+
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.AbstractFunctionPtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.record.formula.functions.Function;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class FuncVarEval extends FunctionEval {
+
+ private AbstractFunctionPtg delegate;
+
+ public FuncVarEval(Ptg funcPtg) {
+ delegate = (AbstractFunctionPtg) funcPtg;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ Eval retval = null;
+ Function f = getFunction();
+ if (f != null)
+ retval = f.evaluate(operands, srcRow, srcCol);
+ else
+ retval = ErrorEval.FUNCTION_NOT_IMPLEMENTED;
+ return retval;
+ }
+
+ public int getNumberOfOperands() {
+ return delegate.getNumberOfOperands();
+ }
+
+ public int getType() {
+ return delegate.getType();
+ }
+
+ public short getFunctionIndex() {
+ return delegate.getFunctionIndex();
+ }
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.functions.*;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public abstract class FunctionEval implements OperationEval {
+ protected static Function[] functions = produceFunctions();
+
+ public Function getFunction() {
+ short fidx = getFunctionIndex();
+ return functions[fidx];
+ }
+
+ public abstract short getFunctionIndex();
+
+ private static Function[] produceFunctions() {
+ Function[] retval = new Function[368];
+ retval[0] = new Count(); // COUNT
+ retval[1] = null; // Specialflag(); // SPECIALFLAG
+ retval[2] = new IsNa(); // ISNA
+ retval[3] = new IsError(); // ISERROR
+ retval[4] = new Sum(); // SUM
+ retval[5] = new Average(); // AVERAGE
+ retval[6] = new Min(); // MIN
+ retval[7] = new Max(); // MAX
+ retval[8] = new Row(); // ROW
+ retval[9] = new Column(); // COLUMN
+ retval[10] = new Na(); // NA
+ retval[11] = new Npv(); // NPV
+ retval[12] = new Stdev(); // STDEV
+ retval[13] = new Dollar(); // DOLLAR
+ retval[14] = new Fixed(); // FIXED
+ retval[15] = new Sin(); // SIN
+ retval[16] = new Cos(); // COS
+ retval[17] = new Tan(); // TAN
+ retval[18] = new Atan(); // ATAN
+ retval[19] = new Pi(); // PI
+ retval[20] = new Sqrt(); // SQRT
+ retval[21] = new Exp(); // EXP
+ retval[22] = new Ln(); // LN
+ retval[23] = new Log10(); // LOG10
+ retval[24] = new Abs(); // ABS
+ retval[25] = new Int(); // INT
+ retval[26] = new Sign(); // SIGN
+ retval[27] = new Round(); // ROUND
+ retval[28] = new Lookup(); // LOOKUP
+ retval[29] = new Index(); // INDEX
+ retval[30] = new Rept(); // REPT
+ retval[31] = new Mid(); // MID
+ retval[32] = new Len(); // LEN
+ retval[33] = new Value(); // VALUE
+ retval[34] = new True(); // TRUE
+ retval[35] = new False(); // FALSE
+ retval[36] = new And(); // AND
+ retval[37] = new Or(); // OR
+ retval[38] = new Not(); // NOT
+ retval[39] = new Mod(); // MOD
+ retval[40] = new Dcount(); // DCOUNT
+ retval[41] = new Dsum(); // DSUM
+ retval[42] = new Daverage(); // DAVERAGE
+ retval[43] = new Dmin(); // DMIN
+ retval[44] = new Dmax(); // DMAX
+ retval[45] = new Dstdev(); // DSTDEV
+ retval[46] = new Var(); // VAR
+ retval[47] = new Dvar(); // DVAR
+ retval[48] = new Text(); // TEXT
+ retval[49] = new Linest(); // LINEST
+ retval[50] = new Trend(); // TREND
+ retval[51] = new Logest(); // LOGEST
+ retval[52] = new Growth(); // GROWTH
+ retval[53] = new Goto(); // GOTO
+ retval[54] = new Halt(); // HALT
+ retval[56] = new Pv(); // PV
+ retval[57] = new Fv(); // FV
+ retval[58] = new Nper(); // NPER
+ retval[59] = new Pmt(); // PMT
+ retval[60] = new Rate(); // RATE
+ retval[61] = new Mirr(); // MIRR
+ retval[62] = new Irr(); // IRR
+ retval[63] = new Rand(); // RAND
+ retval[64] = new Match(); // MATCH
+ retval[65] = new Date(); // DATE
+ retval[66] = new Time(); // TIME
+ retval[67] = new Day(); // DAY
+ retval[68] = new Month(); // MONTH
+ retval[69] = new Year(); // YEAR
+ retval[70] = new Weekday(); // WEEKDAY
+ retval[71] = new Hour(); // HOUR
+ retval[72] = new Minute(); // MINUTE
+ retval[73] = new Second(); // SECOND
+ retval[74] = new Now(); // NOW
+ retval[75] = new Areas(); // AREAS
+ retval[76] = new Rows(); // ROWS
+ retval[77] = new Columns(); // COLUMNS
+ retval[78] = new Offset(); // OFFSET
+ retval[79] = new Absref(); // ABSREF
+ retval[80] = new Relref(); // RELREF
+ retval[81] = new Argument(); // ARGUMENT
+ retval[82] = new Search(); // SEARCH
+ retval[83] = new Transpose(); // TRANSPOSE
+ retval[84] = new org.apache.poi.hssf.record.formula.functions.Error(); // ERROR
+ retval[85] = new Step(); // STEP
+ retval[86] = new Type(); // TYPE
+ retval[87] = new Echo(); // ECHO
+ retval[88] = new Setname(); // SETNAME
+ retval[89] = new Caller(); // CALLER
+ retval[90] = new Deref(); // DEREF
+ retval[91] = new Windows(); // WINDOWS
+ retval[92] = new Series(); // SERIES
+ retval[93] = new Documents(); // DOCUMENTS
+ retval[94] = new Activecell(); // ACTIVECELL
+ retval[95] = new Selection(); // SELECTION
+ retval[96] = new Result(); // RESULT
+ retval[97] = new Atan2(); // ATAN2
+ retval[98] = new Asin(); // ASIN
+ retval[99] = new Acos(); // ACOS
+ retval[100] = new Choose(); // CHOOSE
+ retval[101] = new Hlookup(); // HLOOKUP
+ retval[102] = new Vlookup(); // VLOOKUP
+ retval[103] = new Links(); // LINKS
+ retval[104] = new Input(); // INPUT
+ retval[105] = new Isref(); // ISREF
+ retval[106] = new Getformula(); // GETFORMULA
+ retval[107] = new Getname(); // GETNAME
+ retval[108] = new Setvalue(); // SETVALUE
+ retval[109] = new Log(); // LOG
+ retval[110] = new Exec(); // EXEC
+ retval[111] = new Char(); // CHAR
+ retval[112] = new Lower(); // LOWER
+ retval[113] = new Upper(); // UPPER
+ retval[114] = new Proper(); // PROPER
+ retval[115] = new Left(); // LEFT
+ retval[116] = new Right(); // RIGHT
+ retval[117] = new Exact(); // EXACT
+ retval[118] = new Trim(); // TRIM
+ retval[119] = new Replace(); // REPLACE
+ retval[120] = new Substitute(); // SUBSTITUTE
+ retval[121] = new Code(); // CODE
+ retval[122] = new Names(); // NAMES
+ retval[123] = new Directory(); // DIRECTORY
+ retval[124] = new Find(); // FIND
+ retval[125] = new Cell(); // CELL
+ retval[126] = new Iserr(); // ISERR
+ retval[127] = new Istext(); // ISTEXT
+ retval[128] = new Isnumber(); // ISNUMBER
+ retval[129] = new Isblank(); // ISBLANK
+ retval[130] = new T(); // T
+ retval[131] = new N(); // N
+ retval[132] = new Fopen(); // FOPEN
+ retval[133] = new Fclose(); // FCLOSE
+ retval[134] = new Fsize(); // FSIZE
+ retval[135] = new Freadln(); // FREADLN
+ retval[136] = new Fread(); // FREAD
+ retval[137] = new Fwriteln(); // FWRITELN
+ retval[138] = new Fwrite(); // FWRITE
+ retval[139] = new Fpos(); // FPOS
+ retval[140] = new Datevalue(); // DATEVALUE
+ retval[141] = new Timevalue(); // TIMEVALUE
+ retval[142] = new Sln(); // SLN
+ retval[143] = new Syd(); // SYD
+ retval[144] = new Ddb(); // DDB
+ retval[145] = new Getdef(); // GETDEF
+ retval[146] = new Reftext(); // REFTEXT
+ retval[147] = new Textref(); // TEXTREF
+ retval[148] = new Indirect(); // INDIRECT
+ retval[149] = new Register(); // REGISTER
+ retval[150] = new Call(); // CALL
+ retval[151] = new Addbar(); // ADDBAR
+ retval[152] = new Addmenu(); // ADDMENU
+ retval[153] = new Addcommand(); // ADDCOMMAND
+ retval[154] = new Enablecommand(); // ENABLECOMMAND
+ retval[155] = new Checkcommand(); // CHECKCOMMAND
+ retval[156] = new Renamecommand(); // RENAMECOMMAND
+ retval[157] = new Showbar(); // SHOWBAR
+ retval[158] = new Deletemenu(); // DELETEMENU
+ retval[159] = new Deletecommand(); // DELETECOMMAND
+ retval[160] = new Getchartitem(); // GETCHARTITEM
+ retval[161] = new Dialogbox(); // DIALOGBOX
+ retval[162] = new Clean(); // CLEAN
+ retval[163] = new Mdeterm(); // MDETERM
+ retval[164] = new Minverse(); // MINVERSE
+ retval[165] = new Mmult(); // MMULT
+ retval[166] = new Files(); // FILES
+ retval[167] = new Ipmt(); // IPMT
+ retval[168] = new Ppmt(); // PPMT
+ retval[169] = new Counta(); // COUNTA
+ retval[170] = new Cancelkey(); // CANCELKEY
+ retval[175] = new Initiate(); // INITIATE
+ retval[176] = new Request(); // REQUEST
+ retval[177] = new Poke(); // POKE
+ retval[178] = new Execute(); // EXECUTE
+ retval[179] = new Terminate(); // TERMINATE
+ retval[180] = new Restart(); // RESTART
+ retval[181] = new Help(); // HELP
+ retval[182] = new Getbar(); // GETBAR
+ retval[183] = new Product(); // PRODUCT
+ retval[184] = new Fact(); // FACT
+ retval[185] = new Getcell(); // GETCELL
+ retval[186] = new Getworkspace(); // GETWORKSPACE
+ retval[187] = new Getwindow(); // GETWINDOW
+ retval[188] = new Getdocument(); // GETDOCUMENT
+ retval[189] = new Dproduct(); // DPRODUCT
+ retval[190] = new Isnontext(); // ISNONTEXT
+ retval[191] = new Getnote(); // GETNOTE
+ retval[192] = new Note(); // NOTE
+ retval[193] = new Stdevp(); // STDEVP
+ retval[194] = new Varp(); // VARP
+ retval[195] = new Dstdevp(); // DSTDEVP
+ retval[196] = new Dvarp(); // DVARP
+ retval[197] = new Trunc(); // TRUNC
+ retval[198] = new Islogical(); // ISLOGICAL
+ retval[199] = new Dcounta(); // DCOUNTA
+ retval[200] = new Deletebar(); // DELETEBAR
+ retval[201] = new Unregister(); // UNREGISTER
+ retval[204] = new Usdollar(); // USDOLLAR
+ retval[205] = new Findb(); // FINDB
+ retval[206] = new Searchb(); // SEARCHB
+ retval[207] = new Replaceb(); // REPLACEB
+ retval[208] = new Leftb(); // LEFTB
+ retval[209] = new Rightb(); // RIGHTB
+ retval[210] = new Midb(); // MIDB
+ retval[211] = new Lenb(); // LENB
+ retval[212] = new Roundup(); // ROUNDUP
+ retval[213] = new Rounddown(); // ROUNDDOWN
+ retval[214] = new Asc(); // ASC
+ retval[215] = new Dbcs(); // DBCS
+ retval[216] = new Rank(); // RANK
+ retval[219] = new Address(); // ADDRESS
+ retval[220] = new Days360(); // DAYS360
+ retval[221] = new Today(); // TODAY
+ retval[222] = new Vdb(); // VDB
+ retval[227] = new Median(); // MEDIAN
+ retval[228] = new Sumproduct(); // SUMPRODUCT
+ retval[229] = new Sinh(); // SINH
+ retval[230] = new Cosh(); // COSH
+ retval[231] = new Tanh(); // TANH
+ retval[232] = new Asinh(); // ASINH
+ retval[233] = new Acosh(); // ACOSH
+ retval[234] = new Atanh(); // ATANH
+ retval[235] = new Dget(); // DGET
+ retval[236] = new Createobject(); // CREATEOBJECT
+ retval[237] = new Volatile(); // VOLATILE
+ retval[238] = new Lasterror(); // LASTERROR
+ retval[239] = new Customundo(); // CUSTOMUNDO
+ retval[240] = new Customrepeat(); // CUSTOMREPEAT
+ retval[241] = new Formulaconvert(); // FORMULACONVERT
+ retval[242] = new Getlinkinfo(); // GETLINKINFO
+ retval[243] = new Textbox(); // TEXTBOX
+ retval[244] = new Info(); // INFO
+ retval[245] = new Group(); // GROUP
+ retval[246] = new Getobject(); // GETOBJECT
+ retval[247] = new Db(); // DB
+ retval[248] = new Pause(); // PAUSE
+ retval[250] = new Resume(); // RESUME
+ retval[252] = new Frequency(); // FREQUENCY
+ retval[253] = new Addtoolbar(); // ADDTOOLBAR
+ retval[254] = new Deletetoolbar(); // DELETETOOLBAR
+ retval[255] = new Externalflag(); // EXTERNALFLAG
+ retval[256] = new Resettoolbar(); // RESETTOOLBAR
+ retval[257] = new Evaluate(); // EVALUATE
+ retval[258] = new Gettoolbar(); // GETTOOLBAR
+ retval[259] = new Gettool(); // GETTOOL
+ retval[260] = new Spellingcheck(); // SPELLINGCHECK
+ retval[261] = new Errortype(); // ERRORTYPE
+ retval[262] = new Apptitle(); // APPTITLE
+ retval[263] = new Windowtitle(); // WINDOWTITLE
+ retval[264] = new Savetoolbar(); // SAVETOOLBAR
+ retval[265] = new Enabletool(); // ENABLETOOL
+ retval[266] = new Presstool(); // PRESSTOOL
+ retval[267] = new Registerid(); // REGISTERID
+ retval[268] = new Getworkbook(); // GETWORKBOOK
+ retval[269] = new Avedev(); // AVEDEV
+ retval[270] = new Betadist(); // BETADIST
+ retval[271] = new Gammaln(); // GAMMALN
+ retval[272] = new Betainv(); // BETAINV
+ retval[273] = new Binomdist(); // BINOMDIST
+ retval[274] = new Chidist(); // CHIDIST
+ retval[275] = new Chiinv(); // CHIINV
+ retval[276] = new Combin(); // COMBIN
+ retval[277] = new Confidence(); // CONFIDENCE
+ retval[278] = new Critbinom(); // CRITBINOM
+ retval[279] = new Even(); // EVEN
+ retval[280] = new Expondist(); // EXPONDIST
+ retval[281] = new Fdist(); // FDIST
+ retval[282] = new Finv(); // FINV
+ retval[283] = new Fisher(); // FISHER
+ retval[284] = new Fisherinv(); // FISHERINV
+ retval[285] = new Floor(); // FLOOR
+ retval[286] = new Gammadist(); // GAMMADIST
+ retval[287] = new Gammainv(); // GAMMAINV
+ retval[288] = new Ceiling(); // CEILING
+ retval[289] = new Hypgeomdist(); // HYPGEOMDIST
+ retval[290] = new Lognormdist(); // LOGNORMDIST
+ retval[291] = new Loginv(); // LOGINV
+ retval[292] = new Negbinomdist(); // NEGBINOMDIST
+ retval[293] = new Normdist(); // NORMDIST
+ retval[294] = new Normsdist(); // NORMSDIST
+ retval[295] = new Norminv(); // NORMINV
+ retval[296] = new Normsinv(); // NORMSINV
+ retval[297] = new Standardize(); // STANDARDIZE
+ retval[298] = new Odd(); // ODD
+ retval[299] = new Permut(); // PERMUT
+ retval[300] = new Poisson(); // POISSON
+ retval[301] = new Tdist(); // TDIST
+ retval[302] = new Weibull(); // WEIBULL
+ retval[303] = new Sumxmy2(); // SUMXMY2
+ retval[304] = new Sumx2my2(); // SUMX2MY2
+ retval[305] = new Sumx2py2(); // SUMX2PY2
+ retval[306] = new Chitest(); // CHITEST
+ retval[307] = new Correl(); // CORREL
+ retval[308] = new Covar(); // COVAR
+ retval[309] = new Forecast(); // FORECAST
+ retval[310] = new Ftest(); // FTEST
+ retval[311] = new Intercept(); // INTERCEPT
+ retval[312] = new Pearson(); // PEARSON
+ retval[313] = new Rsq(); // RSQ
+ retval[314] = new Steyx(); // STEYX
+ retval[315] = new Slope(); // SLOPE
+ retval[316] = new Ttest(); // TTEST
+ retval[317] = new Prob(); // PROB
+ retval[318] = new Devsq(); // DEVSQ
+ retval[319] = new Geomean(); // GEOMEAN
+ retval[320] = new Harmean(); // HARMEAN
+ retval[321] = new Sumsq(); // SUMSQ
+ retval[322] = new Kurt(); // KURT
+ retval[323] = new Skew(); // SKEW
+ retval[324] = new Ztest(); // ZTEST
+ retval[325] = new Large(); // LARGE
+ retval[326] = new Small(); // SMALL
+ retval[327] = new Quartile(); // QUARTILE
+ retval[328] = new Percentile(); // PERCENTILE
+ retval[329] = new Percentrank(); // PERCENTRANK
+ retval[330] = new Mode(); // MODE
+ retval[331] = new Trimmean(); // TRIMMEAN
+ retval[332] = new Tinv(); // TINV
+ retval[334] = new Moviecommand(); // MOVIECOMMAND
+ retval[335] = new Getmovie(); // GETMOVIE
+ retval[336] = new Concatenate(); // CONCATENATE
+ retval[337] = new Power(); // POWER
+ retval[338] = new Pivotadddata(); // PIVOTADDDATA
+ retval[339] = new Getpivottable(); // GETPIVOTTABLE
+ retval[340] = new Getpivotfield(); // GETPIVOTFIELD
+ retval[341] = new Getpivotitem(); // GETPIVOTITEM
+ retval[342] = new Radians(); // RADIANS
+ retval[343] = new Degrees(); // DEGREES
+ retval[344] = new Subtotal(); // SUBTOTAL
+ retval[345] = new Sumif(); // SUMIF
+ retval[346] = new Countif(); // COUNTIF
+ retval[347] = new Countblank(); // COUNTBLANK
+ retval[348] = new Scenarioget(); // SCENARIOGET
+ retval[349] = new Optionslistsget(); // OPTIONSLISTSGET
+ retval[350] = new Ispmt(); // ISPMT
+ retval[351] = new Datedif(); // DATEDIF
+ retval[352] = new Datestring(); // DATESTRING
+ retval[353] = new Numberstring(); // NUMBERSTRING
+ retval[354] = new Roman(); // ROMAN
+ retval[355] = new Opendialog(); // OPENDIALOG
+ retval[356] = new Savedialog(); // SAVEDIALOG
+ retval[357] = new Viewget(); // VIEWGET
+ retval[358] = new Getpivotdata(); // GETPIVOTDATA
+ retval[359] = new Hyperlink(); // HYPERLINK
+ retval[360] = new Phonetic(); // PHONETIC
+ retval[361] = new Averagea(); // AVERAGEA
+ retval[362] = new Maxa(); // MAXA
+ retval[363] = new Mina(); // MINA
+ retval[364] = new Stdevpa(); // STDEVPA
+ retval[365] = new Varpa(); // VARPA
+ retval[366] = new Stdeva(); // STDEVA
+ retval[367] = new Vara(); // VARA
+ return retval;
+ }
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.GreaterEqualPtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class GreaterEqualEval extends RelationalOperationEval {
+
+ private GreaterEqualPtg delegate;
+
+ public GreaterEqualEval(Ptg ptg) {
+ this.delegate = (GreaterEqualPtg) ptg;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ ValueEval retval = null;
+
+ RelationalValues rvs = super.doEvaluate(operands, srcRow, srcCol);
+ retval = rvs.ee;
+ int result = 0;
+ if (retval == null) {
+ result = doComparison(rvs.bs);
+ if (result == 0) {
+ result = doComparison(rvs.ss);
+ }
+ if (result == 0) {
+ result = doComparison(rvs.ds);
+ }
+
+ retval = (result >= 0) ? BoolEval.TRUE : BoolEval.FALSE;
+ }
+
+ return retval;
+ }
+
+ public int getNumberOfOperands() {
+ return delegate.getNumberOfOperands();
+ }
+
+ public int getType() {
+ return delegate.getType();
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.GreaterThanPtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class GreaterThanEval extends RelationalOperationEval {
+
+ private GreaterThanPtg delegate;
+
+ public GreaterThanEval(Ptg ptg) {
+ this.delegate = (GreaterThanPtg) ptg;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ ValueEval retval = null;
+
+ RelationalValues rvs = super.doEvaluate(operands, srcRow, srcCol);
+ retval = rvs.ee;
+ int result = 0;
+ if (retval == null) {
+ result = doComparison(rvs.bs);
+ if (result == 0) {
+ result = doComparison(rvs.ss);
+ }
+ if (result == 0) {
+ result = doComparison(rvs.ds);
+ }
+
+ retval = (result > 0) ? BoolEval.TRUE : BoolEval.FALSE;;
+ }
+
+ return retval;
+ }
+
+ public int getNumberOfOperands() {
+ return delegate.getNumberOfOperands();
+ }
+
+ public int getType() {
+ return delegate.getType();
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.LessEqualPtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class LessEqualEval extends RelationalOperationEval {
+
+ private LessEqualPtg delegate;
+
+ public LessEqualEval(Ptg ptg) {
+ this.delegate = (LessEqualPtg) ptg;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ ValueEval retval = null;
+
+ RelationalValues rvs = super.doEvaluate(operands, srcRow, srcCol);
+ retval = rvs.ee;
+ int result = 0;
+ if (retval == null) {
+ result = doComparison(rvs.bs);
+ if (result == 0) {
+ result = doComparison(rvs.ss);
+ }
+ if (result == 0) {
+ result = doComparison(rvs.ds);
+ }
+
+ retval = (result <= 0) ? BoolEval.TRUE : BoolEval.FALSE;;
+ }
+
+ return retval;
+ }
+
+ public int getNumberOfOperands() {
+ return delegate.getNumberOfOperands();
+ }
+
+ public int getType() {
+ return delegate.getType();
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.LessThanPtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class LessThanEval extends RelationalOperationEval {
+
+ private LessThanPtg delegate;
+
+ public LessThanEval(Ptg ptg) {
+ this.delegate = (LessThanPtg) ptg;
+ }
+
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ ValueEval retval = null;
+
+ RelationalValues rvs = super.doEvaluate(operands, srcRow, srcCol);
+ retval = rvs.ee;
+ int result = 0;
+ if (retval == null) {
+ result = doComparison(rvs.bs);
+ if (result == 0) {
+ result = doComparison(rvs.ss);
+ }
+ if (result == 0) {
+ result = doComparison(rvs.ds);
+ }
+
+ retval = (result < 0) ? BoolEval.TRUE : BoolEval.FALSE;;
+ }
+
+ return retval;
+ }
+
+ public int getNumberOfOperands() {
+ return delegate.getNumberOfOperands();
+ }
+
+ public int getType() {
+ return delegate.getType();
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.record.formula.MultiplyPtg;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class MultiplyEval extends NumericOperationEval {
+
+ private MultiplyPtg delegate;
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ public MultiplyEval(Ptg ptg) {
+ delegate = (MultiplyPtg) ptg;
+ }
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ Eval retval = null;
+ double d0 = 0;
+ double d1 = 0;
+ switch (operands.length) {
+ default: // will rarely happen. currently the parser itself fails.
+ retval = ErrorEval.UNKNOWN_ERROR;
+ break;
+ case 2:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ d0 = ((NumericValueEval) ve).getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+
+ if (retval == null) { // no error yet
+ ve = singleOperandEvaluate(operands[1], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ d1 = ((NumericValueEval) ve).getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
+ } // end switch
+
+ if (retval == null) {
+ retval = (Double.isNaN(d0) || Double.isNaN(d1))
+ ? (ValueEval) ErrorEval.VALUE_INVALID
+ : new NumberEval(d0 * d1);
+ }
+ return retval;
+ }
+
+ public int getNumberOfOperands() {
+ return delegate.getNumberOfOperands();
+ }
+
+ public int getType() {
+ return delegate.getType();
+ }
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.NotEqualPtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class NotEqualEval extends RelationalOperationEval {
+
+ private NotEqualPtg delegate;
+
+ public NotEqualEval(Ptg ptg) {
+ this.delegate = (NotEqualPtg) ptg;
+ }
+
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ ValueEval retval = null;
+
+ RelationalValues rvs = super.doEvaluate(operands, srcRow, srcCol);
+ retval = rvs.ee;
+ int result = 0;
+ if (retval == null) {
+ result = doComparison(rvs.bs);
+ if (result == 0) {
+ result = doComparison(rvs.ss);
+ }
+ if (result == 0) {
+ result = doComparison(rvs.ds);
+ }
+
+ retval = (result != 0) ? BoolEval.TRUE : BoolEval.FALSE;
+ }
+
+ return retval;
+ }
+
+ public int getNumberOfOperands() {
+ return delegate.getNumberOfOperands();
+ }
+
+ public int getType() {
+ return delegate.getType();
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.IntPtg;
+import org.apache.poi.hssf.record.formula.NumberPtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class NumberEval implements NumericValueEval, StringValueEval {
+
+ private double value;
+ private String stringValue;
+
+ public NumberEval(Ptg ptg) {
+ if (ptg instanceof IntPtg) {
+ this.value = ((IntPtg) ptg).getValue();
+ }
+ else if (ptg instanceof NumberPtg) {
+ this.value = ((NumberPtg) ptg).getValue();
+ }
+ }
+
+ public NumberEval(double value) {
+ this.value = value;
+ }
+
+ public double getNumberValue() {
+ return value;
+ }
+
+ public String getStringValue() { // TODO: limit to 15 decimal places
+ if (stringValue == null)
+ makeString();
+ return stringValue;
+ }
+
+ protected void makeString() {
+ if (!Double.isNaN(value)) {
+ long lvalue = Math.round(value);
+ if (lvalue == value) {
+ stringValue = String.valueOf(lvalue);
+ }
+ else {
+ stringValue = String.valueOf(value);
+ }
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 14, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public abstract class NumericOperationEval implements OperationEval {
+
+ protected abstract ValueEvalToNumericXlator getXlator();
+
+ protected ValueEval singleOperandEvaluate(Eval eval, int srcRow, short srcCol) {
+ ValueEval retval;
+ if (eval instanceof AreaEval) {
+ AreaEval ae = (AreaEval) eval;
+ if (ae.contains(srcRow, srcCol)) { // circular ref!
+ retval = ErrorEval.CIRCULAR_REF_ERROR;
+ }
+ else if (ae.isRow()) {
+ if (ae.containsColumn(srcCol)) {
+ ValueEval ve = ae.getValueAt(ae.getFirstRow(), srcCol);
+ ve = getXlator().attemptXlateToNumeric(ve);
+ retval = getXlator().attemptXlateToNumeric(ve);
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
+ else if (ae.isColumn()) {
+ if (ae.containsRow(srcRow)) {
+ ValueEval ve = ae.getValueAt(srcRow, ae.getFirstColumn());
+ retval = getXlator().attemptXlateToNumeric(ve);
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
+ else {
+ retval = getXlator().attemptXlateToNumeric((ValueEval) eval);
+ }
+ return retval;
+ }
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public interface NumericValueEval extends ValueEval {
+
+ public abstract double getNumberValue();
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public interface OperationEval extends Eval {
+
+ /*
+ * Read this, this will make your work easier when coding
+ * an "evaluate()"
+ *
+ * Things to note when implementing evaluate():
+ * 1. Check the length of operands
+ * (use "switch(operands[x])" if possible)
+ *
+ * 2. The possible Evals that you can get as args to evaluate are one of:
+ * NumericValueEval, StringValueEval, RefEval, AreaEval
+ * 3. If it is RefEval, the innerValueEval could be one of:
+ * NumericValueEval, StringValueEval, BlankEval
+ * 4. If it is AreaEval, each of the values could be one of:
+ * NumericValueEval, StringValueEval, BlankEval, RefEval
+ *
+ * 5. For numeric functions/operations, keep the result in double
+ * till the end and before returning a new NumberEval, check to see
+ * if the double is a NaN - if NaN, return ErrorEval.ERROR_503
+ */
+ public abstract Eval evaluate(Eval[] evals, int srcCellRow, short srcCellCol);
+
+ public abstract int getNumberOfOperands();
+
+ public abstract int getType();
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.record.formula.PowerPtg;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class PowerEval extends NumericOperationEval {
+
+ private PowerPtg delegate;
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ public PowerEval(Ptg ptg) {
+ delegate = (PowerPtg) ptg;
+ }
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ Eval retval = null;
+ double d0 = 0;
+ double d1 = 0;
+
+ switch (operands.length) {
+ default: // will rarely happen. currently the parser itself fails.
+ retval = ErrorEval.UNKNOWN_ERROR;
+ break;
+ case 2:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ d0 = ((NumericValueEval) ve).getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+
+ if (retval == null) { // no error yet
+ ve = singleOperandEvaluate(operands[1], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ d1 = ((NumericValueEval) ve).getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
+ } // end switch
+
+ if (retval == null) {
+ double p = Math.pow(d0, d1);
+ retval = (Double.isNaN(p))
+ ? (ValueEval) ErrorEval.VALUE_INVALID
+ : new NumberEval(p);
+ }
+ return retval;
+ }
+
+ public int getNumberOfOperands() {
+ return delegate.getNumberOfOperands();
+ }
+
+ public int getType() {
+ return delegate.getType();
+ }
+}
--- /dev/null
+/*
+ * Created on May 9, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.record.formula.ReferencePtg;
+
+/**
+ * @author adeshmukh
+ *
+ */
+public class Ref2DEval implements RefEval {
+
+ private ValueEval value;
+
+ private ReferencePtg delegate;
+
+ private boolean evaluated;
+
+ public Ref2DEval(Ptg ptg, ValueEval value, boolean evaluated) {
+ this.value = value;
+ this.delegate = (ReferencePtg) ptg;
+ this.evaluated = evaluated;
+ }
+
+ public ValueEval getInnerValueEval() {
+ return value;
+ }
+
+ public short getRow() {
+ return delegate.getRow();
+ }
+
+ public short getColumn() {
+ return delegate.getColumn();
+ }
+
+ public boolean isEvaluated() {
+ return evaluated;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 9, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.record.formula.Ref3DPtg;
+
+/**
+ * @author Amol S. Deshmukh
+ *
+ */
+public class Ref3DEval implements RefEval {
+
+ private ValueEval value;
+
+ private Ref3DPtg delegate;
+
+ private boolean evaluated;
+
+ public Ref3DEval(Ptg ptg, ValueEval value, boolean evaluated) {
+ this.value = value;
+ this.delegate = (Ref3DPtg) ptg;
+ this.evaluated = evaluated;
+ }
+
+ public ValueEval getInnerValueEval() {
+ return value;
+ }
+
+ public short getRow() {
+ return delegate.getRow();
+ }
+
+ public short getColumn() {
+ return delegate.getColumn();
+ }
+
+ public boolean isEvaluated() {
+ return evaluated;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 9, 2005
+ *
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+/**
+ * @author Amol S Deshmukh < amolweb at ya hoo dot com >
+ *
+ * RefEval is the super interface for Ref2D and Ref3DEval. Basically a RefEval
+ * impl should contain reference to the original ReferencePtg or Ref3DPtg as
+ * well as the final "value" resulting from the evaluation of the cell
+ * reference. Thus if the HSSFCell has type CELL_TYPE_NUMERIC, the contained
+ * value object should be of type NumberEval; if cell type is CELL_TYPE_STRING,
+ * contained value object should be of type StringEval
+ */
+public interface RefEval extends ValueEval {
+
+ /**
+ * The (possibly evaluated) ValueEval contained
+ * in this RefEval. eg. if cell A1 contains "test"
+ * then in a formula referring to cell A1
+ * the RefEval representing
+ * A1 will return as the getInnerValueEval() the
+ * object of concrete type StringEval
+ * @return
+ */
+ public ValueEval getInnerValueEval();
+
+ /**
+ * returns the column index.
+ * @return
+ */
+ public short getColumn();
+
+ /**
+ * returns the row index.
+ * @return
+ */
+ public short getRow();
+
+ /**
+ * returns true if this RefEval contains an
+ * evaluated value instead of a direct value.
+ * eg. say cell A1 has the value: ="test"
+ * Then the RefEval representing A1 will return
+ * isEvaluated() equal to false. On the other
+ * hand, say cell A1 has the value: =B1 and
+ * B1 has the value "test", then the RefEval
+ * representing A1 will return isEvaluated()
+ * equal to true.
+ * @return
+ */
+ public boolean isEvaluated();
+
+}
--- /dev/null
+/*
+ * Created on May 10, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public abstract class RelationalOperationEval implements OperationEval {
+
+ protected class RelationalValues {
+ public Double[] ds = new Double[2];
+ public Boolean[] bs = new Boolean[2];
+ public String[] ss = new String[3];
+ public ErrorEval ee = null;
+ }
+
+
+ /*
+ * This is a description of how the relational operators apply in MS Excel.
+ * Use this as a guideline when testing/implementing the evaluate methods
+ * for the relational operators Evals.
+ *
+ * Bool > any number. ALWAYS
+ * Bool > any string. ALWAYS
+ * Bool.TRUE > Bool.FALSE
+ *
+ * String > any number. ALWAYS
+ * String > Blank. ALWAYS
+ * String are sorted dictionary wise
+ *
+ * Blank == 0 (numeric)
+ */
+ public RelationalValues doEvaluate(Eval[] operands, int srcRow, short srcCol) {
+ RelationalValues retval = new RelationalValues();
+
+ switch (operands.length) {
+ default:
+ retval.ee = ErrorEval.ERROR_520;
+ break;
+ case 2:
+ internalDoEvaluate(operands, srcRow, srcCol, retval, 0);
+ internalDoEvaluate(operands, srcRow, srcCol, retval, 1);
+ } // end switch
+ return retval;
+ }
+
+ /**
+ * convenience method to avoid code duplication for multiple operands
+ * @param operands
+ * @param srcRow
+ * @param srcCol
+ * @param retval
+ * @param index
+ */
+ private void internalDoEvaluate(Eval[] operands, int srcRow, short srcCol, RelationalValues retval, int index) {
+ if (operands[index] instanceof BoolEval) {
+ BoolEval be = (BoolEval) operands[index];
+ retval.bs[index] = Boolean.valueOf(be.getBooleanValue());
+ }
+ else if (operands[index] instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) operands[index];
+ retval.ds[index] = new Double(ne.getNumberValue());
+ }
+ else if (operands[index] instanceof StringValueEval) {
+ StringValueEval se = (StringValueEval) operands[index];
+ retval.ss[index] = se.getStringValue();
+ }
+ else if (operands[index] instanceof RefEval) {
+ RefEval re = (RefEval) operands[index];
+ ValueEval ve = re.getInnerValueEval();
+ if (ve instanceof BoolEval) {
+ BoolEval be = (BoolEval) ve;
+ retval.bs[index] = Boolean.valueOf(be.getBooleanValue());
+ }
+ else if (ve instanceof BlankEval) {
+ retval.ds[index] = new Double(0);
+ }
+ else if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ retval.ds[index] = new Double(ne.getNumberValue());
+ }
+ else if (ve instanceof StringValueEval) {
+ StringValueEval se = (StringValueEval) ve;
+ retval.ss[index] = se.getStringValue();
+ }
+ }
+ else if (operands[index] instanceof AreaEval) {
+ AreaEval ae = (AreaEval) operands[index];
+ if (ae.isRow()) {
+ if (ae.containsColumn(srcCol)) {
+ ValueEval ve = ae.getValueAt(ae.getFirstRow(), srcCol);
+ if (ve instanceof BoolEval) {
+ BoolEval be = (BoolEval) ve;
+ retval.bs[index] = Boolean.valueOf(be.getBooleanValue());
+ }
+ else if (ve instanceof BlankEval) {
+ retval.ds[index] = new Double(0);
+ }
+ else if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ retval.ds[index] = new Double(ne.getNumberValue());
+ }
+ else if (ve instanceof StringValueEval) {
+ StringValueEval se = (StringValueEval) ve;
+ retval.ss[index] = se.getStringValue();
+ }
+ else {
+ retval.ee = ErrorEval.VALUE_INVALID;
+ }
+ }
+ else {
+ retval.ee = ErrorEval.VALUE_INVALID;
+ }
+ }
+ else if (ae.isColumn()) {
+ if (ae.containsRow(srcRow)) {
+ ValueEval ve = ae.getValueAt(srcRow, ae.getFirstColumn());
+ if (ve instanceof BoolEval) {
+ BoolEval be = (BoolEval) ve;
+ retval.bs[index] = Boolean.valueOf(be.getBooleanValue());
+ }
+ else if (ve instanceof BlankEval) {
+ retval.ds[index] = new Double(0);
+ }
+ else if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ retval.ds[index] = new Double(ne.getNumberValue());
+ }
+ else if (ve instanceof StringValueEval) {
+ StringValueEval se = (StringValueEval) ve;
+ retval.ss[index] = se.getStringValue();
+ }
+ else {
+ retval.ee = ErrorEval.VALUE_INVALID;
+ }
+ }
+ else {
+ retval.ee = ErrorEval.VALUE_INVALID;
+ }
+ }
+ else {
+ retval.ee = ErrorEval.VALUE_INVALID;
+ }
+ }
+ }
+
+ // if both null return 0, else non null wins, else TRUE wins
+ protected int doComparison(Boolean[] bs) {
+ int retval = 0;
+ if (bs[0] != null || bs[1] != null) {
+ retval = bs[0] != null
+ ? bs[1] != null
+ ? bs[0].booleanValue()
+ ? bs[1].booleanValue()
+ ? 0
+ : 1
+ : bs[1].booleanValue()
+ ? -1
+ : 0
+ : 1
+ : bs[1] != null
+ ? -1
+ : 0;
+ }
+ return retval;
+ }
+
+ // if both null return 0, else non null wins, else string compare
+ protected int doComparison(String[] ss) {
+ int retval = 0;
+ if (ss[0] != null || ss[1] != null) {
+ retval = ss[0] != null
+ ? ss[1] != null
+ ? ss[0].compareTo(ss[1])
+ : 1
+ : ss[1] != null
+ ? -1
+ : 0;
+ }
+ return retval;
+ }
+
+ // if both null return 0, else non null wins, else doublevalue compare
+ protected int doComparison(Double[] ds) {
+ int retval = 0;
+ if (ds[0] != null || ds[1] != null) {
+ retval = ds[0] != null
+ ? ds[1] != null
+ ? ds[0].compareTo(ds[1])
+ : 1
+ : ds[1] != null
+ ? -1
+ : 0;
+ }
+ return retval;
+ }
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.record.formula.StringPtg;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class StringEval implements StringValueEval {
+
+ private String value;
+
+ public StringEval(Ptg ptg) {
+ this.value = ((StringPtg) ptg).getValue();
+ }
+
+ public StringEval(String value) {
+ this.value = value;
+ }
+
+ public String getStringValue() {
+ return value;
+ }
+}
--- /dev/null
+/*
+ * Created on May 14, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public abstract class StringOperationEval implements OperationEval {
+
+
+
+ /**
+ * Returns an instanceof StringValueEval or ErrorEval or BlankEval
+ *
+ * @param eval
+ * @param srcRow
+ * @param srcCol
+ * @return
+ */
+ protected ValueEval singleOperandEvaluate(Eval eval, int srcRow, short srcCol) {
+ ValueEval retval;
+ if (eval instanceof AreaEval) {
+ AreaEval ae = (AreaEval) eval;
+ if (ae.contains(srcRow, srcCol)) { // circular ref!
+ retval = ErrorEval.CIRCULAR_REF_ERROR;
+ }
+ else if (ae.isRow()) {
+ if (ae.containsColumn(srcCol)) {
+ ValueEval ve = ae.getValueAt(ae.getFirstRow(), srcCol);
+ retval = internalResolveEval(eval);
+ }
+ else {
+ retval = ErrorEval.NAME_INVALID;
+ }
+ }
+ else if (ae.isColumn()) {
+ if (ae.containsRow(srcRow)) {
+ ValueEval ve = ae.getValueAt(srcRow, ae.getFirstColumn());
+ retval = internalResolveEval(eval);
+ }
+ else {
+ retval = ErrorEval.NAME_INVALID;
+ }
+ }
+ else {
+ retval = ErrorEval.NAME_INVALID;
+ }
+ }
+ else {
+ retval = internalResolveEval(eval);
+ }
+ return retval;
+ }
+
+ private ValueEval internalResolveEval(Eval eval) {
+ ValueEval retval;
+ if (eval instanceof StringValueEval) {
+ retval = (StringValueEval) eval;
+ }
+ else if (eval instanceof RefEval) {
+ RefEval re = (RefEval) eval;
+ ValueEval tve = re.getInnerValueEval();
+ if (tve instanceof StringValueEval || tve instanceof BlankEval) {
+ retval = tve;
+ }
+ else {
+ retval = ErrorEval.NAME_INVALID;
+ }
+ }
+ else if (eval instanceof BlankEval) {
+ retval = (BlankEval) eval;
+ }
+ else {
+ retval = ErrorEval.NAME_INVALID;
+ }
+ return retval;
+ }
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public interface StringValueEval extends ValueEval {
+
+ public String getStringValue();
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.record.formula.SubtractPtg;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class SubtractEval extends NumericOperationEval {
+
+ private SubtractPtg delegate;
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ public SubtractEval(Ptg ptg) {
+ delegate = (SubtractPtg) ptg;
+ }
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ Eval retval = null;
+ double d0 = 0;
+ double d1 = 0;
+ switch (operands.length) {
+ default: // will rarely happen. currently the parser itself fails.
+ retval = ErrorEval.UNKNOWN_ERROR;
+ break;
+ case 2:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ d0 = ((NumericValueEval) ve).getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+
+ if (retval == null) { // no error yet
+ ve = singleOperandEvaluate(operands[1], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ d1 = ((NumericValueEval) ve).getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
+ } // end switch
+
+ if (retval == null) {
+ retval = (Double.isNaN(d0) || Double.isNaN(d1))
+ ? (ValueEval) ErrorEval.VALUE_INVALID
+ : new NumberEval(d0 - d1);
+ }
+ return retval;
+ }
+
+ public int getNumberOfOperands() {
+ return delegate.getNumberOfOperands();
+ }
+
+ public int getType() {
+ return delegate.getType();
+ }
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.record.formula.UnaryMinusPtg;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class UnaryMinusEval extends NumericOperationEval {
+
+ private UnaryMinusPtg delegate;
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+
+ public UnaryMinusEval(Ptg ptg) {
+ this.delegate = (UnaryMinusPtg) ptg;
+ }
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ ValueEval retval = null;
+ double d = 0;
+
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.UNKNOWN_ERROR;
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ d = ((NumericValueEval) ve).getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else if (ve instanceof ErrorEval) {
+ retval = ve;
+ }
+ }
+
+ if (retval == null) {
+ retval = new NumberEval(-d);
+ }
+
+ return retval;
+ }
+
+ public int getNumberOfOperands() {
+ return delegate.getNumberOfOperands();
+ }
+
+ public int getType() {
+ return delegate.getType();
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.record.formula.UnaryPlusPtg;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class UnaryPlusEval implements OperationEval /*extends NumericOperationEval*/ {
+
+ private UnaryPlusPtg delegate;
+
+ /*
+ * COMMENT FOR COMMENTED CODE IN THIS FILE
+ *
+ * The loser who programmed this in excel didnt care to
+ * think about how strings were handled in other numeric
+ * operations when he/she was implementing this operation :P
+ *
+ * Here's what I mean:
+ *
+ * Q. If the formula -"hello" evaluates to #VALUE! in excel, what should
+ * the formula +"hello" evaluate to?
+ *
+ * A. +"hello" evaluates to "hello"
+ *
+ * DO NOT remove the commented code (In memory of the excel
+ * programmer who implemented the UnaryPlus operation :)
+ */
+
+
+// private static final ValueEvalToNumericXlator NUM_XLATOR =
+// new ValueEvalToNumericXlator((short)
+// ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+// | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+// | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+// | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+// | ValueEvalToNumericXlator.STRING_IS_PARSED
+// ));
+
+
+ public UnaryPlusEval(Ptg ptg) {
+ this.delegate = (UnaryPlusPtg) ptg;
+ }
+
+// protected ValueEvalToNumericXlator getXlator() {
+// return NUM_XLATOR;
+// }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.UNKNOWN_ERROR;
+ break;
+ case 1:
+
+// ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+// if (ve instanceof NumericValueEval) {
+// d = ((NumericValueEval) ve).getNumberValue();
+// }
+// else if (ve instanceof BlankEval) {
+// // do nothing
+// }
+// else if (ve instanceof ErrorEval) {
+// retval = ve;
+// }
+ if (operands[0] instanceof RefEval) {
+ RefEval re = (RefEval) operands[0];
+ retval = re.getInnerValueEval();
+ }
+ else if (operands[0] instanceof AreaEval) {
+ AreaEval ae = (AreaEval) operands[0];
+ if (ae.contains(srcRow, srcCol)) { // circular ref!
+ retval = ErrorEval.CIRCULAR_REF_ERROR;
+ }
+ else if (ae.isRow()) {
+ if (ae.containsColumn(srcCol)) {
+ ValueEval ve = ae.getValueAt(ae.getFirstRow(), srcCol);
+ if (ve instanceof RefEval) {
+ ve = ((RefEval) ve).getInnerValueEval();
+ }
+ retval = ve;
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
+ else if (ae.isColumn()) {
+ if (ae.containsRow(srcRow)) {
+ ValueEval ve = ae.getValueAt(ae.getFirstRow(), srcCol);
+ if (ve instanceof RefEval) {
+ ve = ((RefEval) ve).getInnerValueEval();
+ }
+ retval = ve;
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
+ else {
+ retval = (ValueEval) operands[0];
+ }
+ }
+
+ if (retval instanceof BlankEval) {
+ retval = new NumberEval(0);
+ }
+
+ return retval;
+ }
+
+ public int getNumberOfOperands() {
+ return delegate.getNumberOfOperands();
+ }
+
+ public int getType() {
+ return delegate.getType();
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 8, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public interface ValueEval extends Eval {
+
+}
--- /dev/null
+/*
+ * Created on May 14, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class ValueEvalToNumericXlator {
+
+ public static final short STRING_IS_PARSED = 0x0001;
+ public static final short BOOL_IS_PARSED = 0x0002;
+
+ public static final short REF_STRING_IS_PARSED = 0x0004;
+ public static final short REF_BOOL_IS_PARSED = 0x0008;
+
+ public static final short EVALUATED_REF_STRING_IS_PARSED = 0x0010;
+ public static final short EVALUATED_REF_BOOL_IS_PARSED = 0x0020;
+
+ public static final short STRING_TO_BOOL_IS_PARSED = 0x0040;
+ public static final short REF_STRING_TO_BOOL_IS_PARSED = 0x0080;
+
+ public static final short STRING_IS_INVALID_VALUE = 0x0100;
+ public static final short REF_STRING_IS_INVALID_VALUE = 0x200;
+
+ private final short flags;
+
+
+ public ValueEvalToNumericXlator(short flags) {
+ this.flags = flags;
+ }
+
+ /**
+ * returned value can be either A NumericValueEval, BlankEval or ErrorEval.
+ * The params can be either NumberEval, BoolEval, StringEval, or
+ * RefEval
+ * @param eval
+ * @return
+ */
+ public ValueEval attemptXlateToNumeric(ValueEval eval) {
+ ValueEval retval = null;
+
+ if (eval == null) {
+ retval = BlankEval.INSTANCE;
+ }
+
+ // most common case - least worries :)
+ else if (eval instanceof NumberEval) {
+ retval = (NumberEval) eval;
+ }
+
+ // booleval
+ else if (((flags | BOOL_IS_PARSED) > 0) && eval instanceof BoolEval) {
+ retval = (NumericValueEval) eval;
+ }
+
+ // stringeval
+ else if (eval instanceof StringEval) {
+ retval = handleStringEval((StringEval) eval);
+ }
+
+ // refeval
+ else if (eval instanceof RefEval) {
+ retval = handleRefEval((RefEval) eval);
+ }
+
+ //blankeval
+ else if (eval instanceof BlankEval) {
+ retval = eval;
+ }
+
+ // erroreval
+ else if (eval instanceof ErrorEval) {
+ retval = eval;
+ }
+
+ // probably AreaEval? then not acceptable.
+ else {
+ throw new RuntimeException("Invalid ValueEval type passed for conversion: " + eval.getClass());
+ }
+ return retval;
+ }
+
+ /**
+ * uses the relevant flags to decode the supplied RefVal
+ * @param eval
+ * @return
+ */
+ private ValueEval handleRefEval(RefEval reval) {
+ ValueEval retval = null;
+ ValueEval eval = (ValueEval) reval.getInnerValueEval();
+
+ // most common case - least worries :)
+ if (eval instanceof NumberEval) {
+ retval = (NumberEval) eval; // the cast is correct :)
+ }
+
+ // booleval
+ else if (((flags | REF_BOOL_IS_PARSED) > 0) && eval instanceof BoolEval) {
+ retval = (NumericValueEval) eval;
+ }
+
+ // stringeval
+ else if (eval instanceof StringEval) {
+ retval = handleRefStringEval((StringEval) eval);
+ }
+
+ //blankeval
+ else if (eval instanceof BlankEval) {
+ retval = eval;
+ }
+
+ // erroreval
+ else if (eval instanceof ErrorEval) {
+ retval = eval;
+ }
+
+ // probably AreaEval or another RefEval? then not acceptable.
+ else {
+ throw new RuntimeException("Invalid ValueEval type passed for conversion: " + eval.getClass());
+ }
+ return retval;
+ }
+
+ /**
+ * uses the relevant flags to decode the StringEval
+ * @param eval
+ * @return
+ */
+ private ValueEval handleStringEval(StringEval eval) {
+ ValueEval retval = null;
+ if ((flags | STRING_IS_PARSED) > 0) {
+ StringEval sve = (StringEval) eval;
+ String s = sve.getStringValue();
+ try {
+ double d = Double.parseDouble(s);
+ retval = new NumberEval(d);
+ }
+ catch (Exception e) { retval = ErrorEval.VALUE_INVALID; }
+ }
+ else if ((flags | STRING_TO_BOOL_IS_PARSED) > 0) {
+ StringEval sve = (StringEval) eval;
+ String s = sve.getStringValue();
+ try {
+ boolean b = Boolean.getBoolean(s);
+ retval = b ? BoolEval.TRUE : BoolEval.FALSE;
+ }
+ catch (Exception e) { retval = ErrorEval.VALUE_INVALID; }
+ }
+
+ // strings are errors?
+ else if ((flags | STRING_IS_INVALID_VALUE) > 0) {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+
+ // ignore strings
+ else {
+ retval = BlankEval.INSTANCE;
+ }
+ return retval;
+ }
+
+ /**
+ * uses the relevant flags to decode the StringEval
+ * @param eval
+ * @return
+ */
+ private ValueEval handleRefStringEval(StringEval eval) {
+ ValueEval retval = null;
+ if ((flags | REF_STRING_IS_PARSED) > 0) {
+ StringEval sve = (StringEval) eval;
+ String s = sve.getStringValue();
+ try {
+ double d = Double.parseDouble(s);
+ retval = new NumberEval(d);
+ }
+ catch (Exception e) { retval = ErrorEval.VALUE_INVALID; }
+ }
+ else if ((flags | REF_STRING_TO_BOOL_IS_PARSED) > 0) {
+ StringEval sve = (StringEval) eval;
+ String s = sve.getStringValue();
+ try {
+ boolean b = Boolean.getBoolean(s);
+ retval = retval = b ? BoolEval.TRUE : BoolEval.FALSE;;
+ }
+ catch (Exception e) { retval = ErrorEval.VALUE_INVALID; }
+ }
+
+ // strings are errors?
+ else if ((flags | REF_STRING_IS_INVALID_VALUE) > 0) {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+
+ // ignore strings
+ else {
+ retval = BlankEval.INSTANCE;
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Abs extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(Math.abs(d));
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Absref extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Acos extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ d = Math.acos(d);
+ retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ * Support for hyperbolic trig functions was added as a part of
+ * Java distribution only in JDK1.5. This class uses custom
+ * naive implementation based on formulas at:
+ * http://www.math2.org/math/trig/hyperbolics.htm
+ * These formulas seem to agree with excel's implementation.
+ *
+ */
+public class Acosh extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ }
+
+ if (retval == null) {
+ d = Math.log(Math.sqrt(Math.pow(d, 2) - 1) + d);
+ retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.NUM_ERROR : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Activecell extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Addbar extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Addcommand extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Addmenu extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Address extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Addtoolbar extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 9, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.AreaEval;
+import org.apache.poi.hssf.record.formula.eval.BoolEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.StringEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+
+/**
+ * @author
+ *
+ */
+public class And extends BooleanFunction {
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ ValueEval retval = null;
+ boolean b = true;
+ boolean atleastOneNonBlank = false;
+
+ /*
+ * Note: do not abort the loop if b is false, since we could be
+ * dealing with errorevals later.
+ */
+ outer:
+ for (int i=0, iSize=operands.length; i<iSize; i++) {
+ if (operands[i] instanceof AreaEval) {
+ AreaEval ae = (AreaEval) operands[i];
+ ValueEval[] values = ae.getValues();
+ for (int j=0, jSize=values.length; j<jSize; j++) {
+ ValueEval tempVe = tempVe = singleOperandEvaluate(values[j], srcRow, srcCol, true);
+ if (tempVe instanceof BoolEval) {
+ b = b && ((BoolEval) tempVe).getBooleanValue();
+ atleastOneNonBlank = true;
+ }
+ else if (tempVe instanceof ErrorEval) {
+ retval = tempVe;
+ break outer;
+ }
+ }
+ }
+ else {
+ ValueEval tempVe = singleOperandEvaluate(operands[i], srcRow, srcCol, false);
+ if (tempVe instanceof BoolEval) {
+ b = b && ((BoolEval) tempVe).getBooleanValue();
+ atleastOneNonBlank = true;
+ }
+ else if (tempVe instanceof StringEval) {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ else if (tempVe instanceof ErrorEval) {
+ retval = tempVe;
+ break outer;
+ }
+ }
+ }
+
+ if (!atleastOneNonBlank) {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+
+ if (retval == null) { // if no error
+ retval = b ? BoolEval.TRUE : BoolEval.FALSE;
+ }
+
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Apptitle extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Areas extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Argument extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Asc extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Asin extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ d = Math.asin(d);
+ retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ * Support for hyperbolic trig functions was added as a part of
+ * Java distribution only in JDK1.5. This class uses custom
+ * naive implementation based on formulas at:
+ * http://www.math2.org/math/trig/hyperbolics.htm
+ * These formulas seem to agree with excel's implementation.
+ *
+ */
+public class Asinh extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ d = Math.log(Math.sqrt(Math.pow(d, 2) + 1) + d);
+ retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.NUM_ERROR : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Atan extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ d = Math.atan(d);
+ retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Atan2 extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d0 = 0;
+ double d1 = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ break;
+ case 2:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d0 = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+
+ if (retval == null) {
+ ve = singleOperandEvaluate(operands[1], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d1 = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+ }
+
+ if (retval == null) {
+ double d = (d0 == d1 && d1 == 0) ? Double.NaN : Math.atan2(d1, d0);
+ retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ * Support for hyperbolic trig functions was added as a part of
+ * Java distribution only in JDK1.5. This class uses custom
+ * naive implementation based on formulas at:
+ * http://www.math2.org/math/trig/hyperbolics.htm
+ * These formulas seem to agree with excel's implementation.
+ *
+ */
+public class Atanh extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ d = Math.log((1 + d)/(1 - d)) / 2;
+ retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.NUM_ERROR : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Avedev extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Average extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Averagea extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Betadist extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Betainv extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Binomdist extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.BoolEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.RefEval;
+import org.apache.poi.hssf.record.formula.eval.StringEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ * Here are the general rules concerning Boolean functions:
+ * <ol>
+ * <li> Blanks are not either true or false
+ * <li> Strings are not either true or false (even strings "true"
+ * or "TRUE" or "0" etc.)
+ * <li> Numbers: 0 is false. Any other number is TRUE.
+ * <li> References are evaluated and above rules apply.
+ * <li> Areas: Individual cells in area are evaluated and checked to
+ * see if they are blanks, strings etc.
+ * </ol>
+ */
+public abstract class BooleanFunction implements Function {
+
+ protected ValueEval singleOperandEvaluate(Eval eval, int srcRow, short srcCol, boolean stringsAreBlanks) {
+ ValueEval retval;
+
+ if (eval instanceof RefEval) {
+ RefEval re = (RefEval) eval;
+ ValueEval ve = re.getInnerValueEval();
+ retval = internalResolve(ve, true);
+ }
+ else {
+ retval = internalResolve(eval, stringsAreBlanks);
+ }
+
+ return retval;
+ }
+
+ private ValueEval internalResolve(Eval ve, boolean stringsAreBlanks) {
+ ValueEval retval = null;
+
+ // blankeval is returned as is
+ if (ve instanceof BlankEval) {
+ retval = BlankEval.INSTANCE;
+ }
+
+ // stringeval
+ else if (ve instanceof StringEval) {
+ retval = stringsAreBlanks ? (ValueEval) BlankEval.INSTANCE : (StringEval) ve;
+ }
+
+ // bools are bools :)
+ else if (ve instanceof BoolEval) {
+ retval = (BoolEval) ve;
+ }
+
+ // convert numbers to bool
+ else if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ double d = ne.getNumberValue();
+ retval = Double.isNaN(d)
+ ? (ValueEval) ErrorEval.VALUE_INVALID
+ : (d != 0)
+ ? BoolEval.TRUE
+ : BoolEval.FALSE;
+ }
+
+ // since refevals
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+
+ return retval;
+
+ }
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Call extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Caller extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Cancelkey extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+
+/**
+ * @author
+ *
+ */
+public class Ceiling extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Cell extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Char extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Checkcommand extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Chidist extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Chiinv extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Chitest extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Choose extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Clean extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Code extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Column extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Columns extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Combin extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Concatenate extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Confidence extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Correl extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Cos extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ d = Math.cos(d);
+ retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Cosh extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ double ePowX = Math.pow(E, d);
+ double ePowNegX = Math.pow(E, -d);
+ d = (ePowX + ePowNegX) / 2;
+ retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Count extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Counta extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Countblank extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Countif extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Covar extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Createobject extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Critbinom extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Customrepeat extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Customundo extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Date extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Datedif extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Datestring extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Datevalue extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Daverage extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Day extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Days360 extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Db extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Dbcs extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Dcount extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Dcounta extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Ddb extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+
+/**
+ *
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ * This is the default implementation of a Function class.
+ * The default behaviour is to return a non-standard ErrorEval
+ * "ErrorEval.FUNCTION_NOT_IMPLEMENTED". This error should alert
+ * the user that the formula contained a function that is not
+ * yet implemented.
+ */
+public abstract class DefaultFunctionImpl implements Function {
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ return ErrorEval.FUNCTION_NOT_IMPLEMENTED;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Degrees extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ d = Math.toDegrees(d);
+ retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Deletebar extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Deletecommand extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Deletemenu extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Deletetoolbar extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Deref extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Devsq extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Dget extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Dialogbox extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Directory extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Dmax extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Dmin extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Documents extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Dollar extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Dproduct extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Dstdev extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Dstdevp extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Dsum extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Dvar extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Dvarp extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Echo extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Enablecommand extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Enabletool extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Error extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Errortype extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Evaluate extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Even extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ if (!Double.isNaN(d) && !Double.isInfinite(d)) {
+ d = (d==0)
+ ? 0
+ : (((long) (d/2))*2 == d)
+ ? d
+ : (d < 0)
+ ? ((((long) (d/2))<<1)-2)
+ : ((((long) (d/2))<<1)+2);
+ }
+ retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Exact extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Exec extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Execute extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Exp extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ d = Math.pow(E, d);
+ retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Expondist extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Externalflag extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Fact extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BoolEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class False implements Function {
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ ValueEval retval;
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 0:
+ retval = BoolEval.FALSE;
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Fclose extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Fdist extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Files extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Find extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Findb extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Finv extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Fisher extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Fisherinv extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Fixed extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Floor extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Fopen extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Forecast extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Formulaconvert extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Fpos extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Fread extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Freadln extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Frequency extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Fsize extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Ftest extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 9, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.Eval;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ * Function serves as a marker interface.
+ */
+public interface Function {
+
+ public Eval evaluate(Eval[] evals, int srcCellRow, short srcCellCol);
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Fv extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Fwrite extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Fwriteln extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Gammadist extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Gammainv extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Gammaln extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Geomean extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Getbar extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Getcell extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Getchartitem extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Getdef extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Getdocument extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Getformula extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Getlinkinfo extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Getmovie extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Getname extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Getnote extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Getobject extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Getpivotdata extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Getpivotfield extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Getpivotitem extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Getpivottable extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Gettool extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Gettoolbar extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Getwindow extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Getworkbook extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Getworkspace extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Goto extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Group extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Growth extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Halt extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Harmean extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Help extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Hlookup extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Hour extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Hyperlink extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Hypgeomdist extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Index extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Indirect extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Info extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Initiate extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Input extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Int extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ if (d < 0) {
+ d = Math.round(d-0.5);
+ }
+ retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval((long) d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Intercept extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Ipmt extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Irr extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class IsError extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class IsNa extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Isblank extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Iserr extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Islogical extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Isnontext extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Isnumber extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Ispmt extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Isref extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Istext extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Kurt extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Large extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Lasterror extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Left extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Leftb extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Len extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Lenb extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Linest extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Links extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Ln extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ d = Math.log(d);
+ retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ * Log: LOG(number,[base])
+ */
+public class Log extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ private static final double DEFAULT_BASE = 10;
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ double base = DEFAULT_BASE;
+ double num = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ break;
+ case 2: // second arg is base
+ ValueEval ve = singleOperandEvaluate(operands[1], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ base = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+
+ case 1: // first arg is number
+ if (retval == null) {
+ ValueEval vev = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (vev instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) vev;
+ num = ne.getNumberValue();
+ }
+ else if (vev instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+ }
+
+ if (retval == null) {
+ d = (base == E)
+ ? Math.log(num)
+ : Math.log(num) / Math.log(base);
+ retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Log10 extends NumericFunction {
+ private static final double LOG_10_TO_BASE_e = Math.log(10);
+
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ d = Math.log(d) / LOG_10_TO_BASE_e;
+ retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Logest extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Loginv extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Lognormdist extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Lookup extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Lower extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Match extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Max extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Maxa extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Mdeterm extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Median extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Mid extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Midb extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Min extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Mina extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Minute extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Minverse extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Mirr extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Mmult extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Mod extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Mode extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Month extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Moviecommand extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class N extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Na extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Names extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Negbinomdist extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Normdist extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Norminv extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Normsdist extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Normsinv extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 9, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+
+/**
+ * @author
+ *
+ */
+public class Not extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Note extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Now extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Nper extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Npv extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Numberstring extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 14, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.AreaEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public abstract class NumericFunction implements Function {
+
+ protected static final double E = Math.E;
+ protected static final double PI = Math.PI;
+
+ protected abstract ValueEvalToNumericXlator getXlator();
+
+ protected ValueEval singleOperandEvaluate(Eval eval, int srcRow, short srcCol) {
+ ValueEval retval;
+ if (eval instanceof AreaEval) {
+ AreaEval ae = (AreaEval) eval;
+ if (ae.contains(srcRow, srcCol)) { // circular ref!
+ retval = ErrorEval.CIRCULAR_REF_ERROR;
+ }
+ else if (ae.isRow()) {
+ if (ae.containsColumn(srcCol)) {
+ ValueEval ve = ae.getValueAt(ae.getFirstRow(), srcCol);
+ ve = getXlator().attemptXlateToNumeric(ve);
+ retval = getXlator().attemptXlateToNumeric(ve);
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
+ else if (ae.isColumn()) {
+ if (ae.containsRow(srcRow)) {
+ ValueEval ve = ae.getValueAt(srcRow, ae.getFirstColumn());
+ retval = getXlator().attemptXlateToNumeric(ve);
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
+ else {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+ }
+ else {
+ retval = getXlator().attemptXlateToNumeric((ValueEval) eval);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Odd extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ if (!Double.isNaN(d) && !Double.isInfinite(d)) {
+ d = (d==0)
+ ? 1
+ : ((((long) d) - 1) % 2 == 0)
+ ? d
+ : (d < 0)
+ ? ((((long) (d/2))<<1)-1)
+ : ((((long) (d/2))<<1)+1);
+ }
+ retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Offset extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Opendialog extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Optionslistsget extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 9, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.AreaEval;
+import org.apache.poi.hssf.record.formula.eval.BoolEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+
+/**
+ * @author
+ *
+ */
+public class Or extends BooleanFunction {
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ ValueEval retval = null;
+ boolean b = false;
+ boolean atleastOneNonBlank = false;
+
+ /*
+ * Note: do not abort the loop if b is true, since we could be
+ * dealing with errorevals later.
+ */
+ outer:
+ for (int i=0, iSize=operands.length; i<iSize; i++) {
+ if (operands[i] instanceof AreaEval) {
+ AreaEval ae = (AreaEval) operands[i];
+ ValueEval[] values = ae.getValues();
+ for (int j=0, jSize=values.length; j<jSize; j++) {
+ ValueEval tempVe = tempVe = singleOperandEvaluate(values[j], srcRow, srcCol, true);
+ if (tempVe instanceof BoolEval) {
+ b = b || ((BoolEval) tempVe).getBooleanValue();
+ atleastOneNonBlank = true;
+ }
+ else if (tempVe instanceof ErrorEval) {
+ retval = tempVe;
+ break outer;
+ }
+ }
+ }
+ else {
+ ValueEval tempVe = singleOperandEvaluate(operands[i], srcRow, srcCol, false);
+ if (tempVe instanceof BoolEval) {
+ b = b || ((BoolEval) tempVe).getBooleanValue();
+ atleastOneNonBlank = true;
+ }
+ else if (tempVe instanceof ErrorEval) {
+ retval = tempVe;
+ break outer;
+ }
+ }
+ }
+
+ if (!atleastOneNonBlank) {
+ retval = ErrorEval.VALUE_INVALID;
+ }
+
+ if (retval == null) { // if no error
+ retval = b ? BoolEval.TRUE : BoolEval.FALSE;
+ }
+
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Pause extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Pearson extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Percentile extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Percentrank extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Permut extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Phonetic extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Pi implements Function {
+
+ private static final NumberEval PI_EVAL = new NumberEval(Math.PI);
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ ValueEval retval;
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 0:
+ retval = PI_EVAL;
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Pivotadddata extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Pmt extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Poisson extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Poke extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Power extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d0 = 0;
+ double d1 = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 2:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d0 = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+
+ if (retval == null) {
+ ValueEval vev = singleOperandEvaluate(operands[1], srcRow, srcCol);
+ if (vev instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) vev;
+ d1 = ne.getNumberValue();
+ }
+ else if (vev instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+ }
+
+ if (retval == null) {
+ double d = Math.pow(d0, d1);
+ retval = (Double.isNaN(d) || Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Ppmt extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Presstool extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Prob extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Product extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Proper extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Pv extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Quartile extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Radians extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ d = Math.toRadians(d);
+ retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Rand implements Function {
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ ValueEval retval;
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 0:
+ retval = new NumberEval(Math.random());
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Rank extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Rate extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Reftext extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Register extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Registerid extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Relref extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Renamecommand extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Replace extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Replaceb extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Rept extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Request extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Resettoolbar extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Restart extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Result extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Resume extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Right extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Rightb extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Roman extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Round extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Rounddown extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Roundup extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Row extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Rows extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Rsq extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Savedialog extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Savetoolbar extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Scenarioget extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Search extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Searchb extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Second extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Selection extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Series extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Setname extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Setvalue extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Showbar extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author
+ *
+ */
+public class Sign extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ retval = (Double.isNaN(d) || Double.isInfinite(d))
+ ? (ValueEval) ErrorEval.VALUE_INVALID
+ : (d == 0)
+ ? new NumberEval(0)
+ : (d < 0)
+ ? new NumberEval(-1)
+ : new NumberEval(1);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Sin extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ d = Math.sin(d);
+ retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Sinh extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ double ePowX = Math.pow(E, d);
+ double ePowNegX = Math.pow(E, -d);
+ d = (ePowX - ePowNegX) / 2;
+ retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Skew extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Sln extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Slope extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Small extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Spellingcheck extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Sqrt extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ d = Math.sqrt(d);
+ retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Standardize extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Stdev extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Stdeva extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Stdevp extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Stdevpa extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Step extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Steyx extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Substitute extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Subtotal extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Sum extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Sumif extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Sumproduct extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Sumsq extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Sumx2my2 extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Sumx2py2 extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Sumxmy2 extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Syd extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class T extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Tan extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ d = Math.tan(d);
+ retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class Tanh extends NumericFunction {
+
+ private static final ValueEvalToNumericXlator NUM_XLATOR =
+ new ValueEvalToNumericXlator((short)
+ ( ValueEvalToNumericXlator.BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
+ | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
+ | ValueEvalToNumericXlator.STRING_IS_PARSED
+ ));
+
+ protected ValueEvalToNumericXlator getXlator() {
+ return NUM_XLATOR;
+ }
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ double d = 0;
+ ValueEval retval = null;
+
+ switch (operands.length) {
+ default:
+ break;
+ case 1:
+ ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
+ if (ve instanceof NumericValueEval) {
+ NumericValueEval ne = (NumericValueEval) ve;
+ d = ne.getNumberValue();
+ }
+ else if (ve instanceof BlankEval) {
+ // do nothing
+ }
+ else {
+ retval = ErrorEval.NUM_ERROR;
+ }
+ }
+
+ if (retval == null) {
+ double ePowX = Math.pow(E, d);
+ double ePowNegX = Math.pow(E, -d);
+ d = (ePowX - ePowNegX) / (ePowX + ePowNegX);
+ retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Tdist extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Terminate extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Text extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Textbox extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Textref extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Time extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Timevalue extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Tinv extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Today extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Transpose extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Trend extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Trim extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Trimmean extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 6, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.BoolEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class True implements Function {
+
+ public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
+ ValueEval retval;
+ switch (operands.length) {
+ default:
+ retval = ErrorEval.VALUE_INVALID;
+ break;
+ case 0:
+ retval = BoolEval.TRUE;
+ }
+ return retval;
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Trunc extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Ttest extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Type extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Unregister extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Upper extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Usdollar extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Value extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Var extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Vara extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Varp extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Varpa extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Vdb extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Viewget extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Vlookup extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Volatile extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Weekday extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Weibull extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Windows extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Windowtitle extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Year extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 15, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+/**
+ * @author
+ *
+ */
+public class Ztest extends DefaultFunctionImpl {
+
+}
--- /dev/null
+/*
+ * Created on May 5, 2005
+ *
+ */
+package org.apache.poi.hssf.usermodel;
+
+import java.io.FileInputStream;
+import java.lang.reflect.Constructor;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Stack;
+
+import org.apache.poi.hssf.model.FormulaParser;
+import org.apache.poi.hssf.record.formula.AddPtg;
+import org.apache.poi.hssf.record.formula.Area3DPtg;
+import org.apache.poi.hssf.record.formula.AreaPtg;
+import org.apache.poi.hssf.record.formula.AttrPtg;
+import org.apache.poi.hssf.record.formula.BoolPtg;
+import org.apache.poi.hssf.record.formula.ConcatPtg;
+import org.apache.poi.hssf.record.formula.ControlPtg;
+import org.apache.poi.hssf.record.formula.DividePtg;
+import org.apache.poi.hssf.record.formula.EqualPtg;
+import org.apache.poi.hssf.record.formula.FuncPtg;
+import org.apache.poi.hssf.record.formula.FuncVarPtg;
+import org.apache.poi.hssf.record.formula.GreaterEqualPtg;
+import org.apache.poi.hssf.record.formula.GreaterThanPtg;
+import org.apache.poi.hssf.record.formula.IntPtg;
+import org.apache.poi.hssf.record.formula.LessEqualPtg;
+import org.apache.poi.hssf.record.formula.LessThanPtg;
+import org.apache.poi.hssf.record.formula.MemErrPtg;
+import org.apache.poi.hssf.record.formula.MissingArgPtg;
+import org.apache.poi.hssf.record.formula.MultiplyPtg;
+import org.apache.poi.hssf.record.formula.NamePtg;
+import org.apache.poi.hssf.record.formula.NameXPtg;
+import org.apache.poi.hssf.record.formula.NotEqualPtg;
+import org.apache.poi.hssf.record.formula.NumberPtg;
+import org.apache.poi.hssf.record.formula.OperationPtg;
+import org.apache.poi.hssf.record.formula.ParenthesisPtg;
+import org.apache.poi.hssf.record.formula.PowerPtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.record.formula.Ref3DPtg;
+import org.apache.poi.hssf.record.formula.ReferencePtg;
+import org.apache.poi.hssf.record.formula.StringPtg;
+import org.apache.poi.hssf.record.formula.SubtractPtg;
+import org.apache.poi.hssf.record.formula.UnaryMinusPtg;
+import org.apache.poi.hssf.record.formula.UnaryPlusPtg;
+import org.apache.poi.hssf.record.formula.UnionPtg;
+import org.apache.poi.hssf.record.formula.UnknownPtg;
+import org.apache.poi.hssf.record.formula.eval.AddEval;
+import org.apache.poi.hssf.record.formula.eval.Area2DEval;
+import org.apache.poi.hssf.record.formula.eval.Area3DEval;
+import org.apache.poi.hssf.record.formula.eval.AreaEval;
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.BoolEval;
+import org.apache.poi.hssf.record.formula.eval.ConcatEval;
+import org.apache.poi.hssf.record.formula.eval.DivideEval;
+import org.apache.poi.hssf.record.formula.eval.EqualEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.FuncVarEval;
+import org.apache.poi.hssf.record.formula.eval.GreaterEqualEval;
+import org.apache.poi.hssf.record.formula.eval.GreaterThanEval;
+import org.apache.poi.hssf.record.formula.eval.LessEqualEval;
+import org.apache.poi.hssf.record.formula.eval.LessThanEval;
+import org.apache.poi.hssf.record.formula.eval.MultiplyEval;
+import org.apache.poi.hssf.record.formula.eval.NotEqualEval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.OperationEval;
+import org.apache.poi.hssf.record.formula.eval.PowerEval;
+import org.apache.poi.hssf.record.formula.eval.Ref2DEval;
+import org.apache.poi.hssf.record.formula.eval.Ref3DEval;
+import org.apache.poi.hssf.record.formula.eval.RefEval;
+import org.apache.poi.hssf.record.formula.eval.StringEval;
+import org.apache.poi.hssf.record.formula.eval.SubtractEval;
+import org.apache.poi.hssf.record.formula.eval.UnaryMinusEval;
+import org.apache.poi.hssf.record.formula.eval.UnaryPlusEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.util.CellReference;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ * Limitations: Unfortunately, cyclic references will cause stackoverflow
+ * exception
+ */
+public class HSSFFormulaEvaluator {
+
+ // params to lookup the right constructor using reflection
+ private static final Class[] OPERATION_CONSTRUCTOR_CLASS_ARRAY = new Class[] { Ptg.class };
+
+ private static final Class[] VALUE_CONTRUCTOR_CLASS_ARRAY = new Class[] { Ptg.class };
+
+ private static final Class[] AREA_CONSTRUCTOR_CLASS_ARRAY = new Class[] { Ptg.class, ValueEval[].class };
+
+ private static final Class[] AREA3D_CONSTRUCTOR_CLASS_ARRAY = new Class[] { Ptg.class, ValueEval[].class };
+
+ private static final Class[] REFERENCE_CONSTRUCTOR_CLASS_ARRAY = new Class[] { Ptg.class, ValueEval.class };
+
+ private static final Class[] REF3D_CONSTRUCTOR_CLASS_ARRAY = new Class[] { Ptg.class, ValueEval.class };
+
+ // Maps for mapping *Eval to *Ptg
+ private static final Map VALUE_EVALS_MAP = new HashMap();
+
+ private static final Map OPERATION_EVALS_MAP = new HashMap();
+
+ /*
+ * If you dont like this map, join the club :) I did this becoz it was
+ * desired to keep the FormulaEvaluator separate from FormulaParser and
+ * related classes in the CVS-HEAD. So now we need some mapping between the
+ * Ptg tokens that the FormulaParser returns and the *Eval classes taht are
+ * used by the FormulaEvaluator - hence the following :)
+ */
+ static {
+ VALUE_EVALS_MAP.put(BoolPtg.class, BoolEval.class);
+ VALUE_EVALS_MAP.put(IntPtg.class, NumberEval.class);
+ VALUE_EVALS_MAP.put(NumberPtg.class, NumberEval.class);
+ VALUE_EVALS_MAP.put(StringPtg.class, StringEval.class);
+
+ OPERATION_EVALS_MAP.put(AddPtg.class, AddEval.class);
+ OPERATION_EVALS_MAP.put(ConcatPtg.class, ConcatEval.class);
+ OPERATION_EVALS_MAP.put(DividePtg.class, DivideEval.class);
+ OPERATION_EVALS_MAP.put(EqualPtg.class, EqualEval.class);
+ //OPERATION_EVALS_MAP.put(ExpPtg.class, ExpEval.class); // TODO: check
+ // this
+ OPERATION_EVALS_MAP.put(FuncPtg.class, FuncVarEval.class); // TODO:
+ // check this
+ OPERATION_EVALS_MAP.put(FuncVarPtg.class, FuncVarEval.class);
+ OPERATION_EVALS_MAP.put(GreaterEqualPtg.class, GreaterEqualEval.class);
+ OPERATION_EVALS_MAP.put(GreaterThanPtg.class, GreaterThanEval.class);
+ OPERATION_EVALS_MAP.put(LessEqualPtg.class, LessEqualEval.class);
+ OPERATION_EVALS_MAP.put(LessThanPtg.class, LessThanEval.class);
+ OPERATION_EVALS_MAP.put(MultiplyPtg.class, MultiplyEval.class);
+ OPERATION_EVALS_MAP.put(NotEqualPtg.class, NotEqualEval.class);
+ OPERATION_EVALS_MAP.put(PowerPtg.class, PowerEval.class);
+ OPERATION_EVALS_MAP.put(SubtractPtg.class, SubtractEval.class);
+ OPERATION_EVALS_MAP.put(UnaryMinusPtg.class, UnaryMinusEval.class);
+ OPERATION_EVALS_MAP.put(UnaryPlusPtg.class, UnaryPlusEval.class);
+
+ }
+
+
+ protected HSSFRow row;
+ protected HSSFSheet sheet;
+ protected HSSFWorkbook workbook;
+
+ public HSSFFormulaEvaluator(HSSFSheet sheet, HSSFWorkbook workbook) {
+ this.sheet = sheet;
+ this.workbook = workbook;
+ }
+
+ public void setCurrentRow(HSSFRow row) {
+ this.row = row;
+ }
+
+
+ /**
+ * If cell contains a formula, the formula is evaluated and returned,
+ * else the CellValue simply copies the appropriate cell value from
+ * the cell and also its cell type. This method should be preferred over
+ * evaluateInCell() when the call should not modify the contents of the
+ * original cell.
+ * @param cell
+ * @return
+ */
+ public CellValue evaluate(HSSFCell cell) {
+ CellValue retval = null;
+ if (cell != null) {
+ switch (cell.getCellType()) {
+ case HSSFCell.CELL_TYPE_BLANK:
+ retval = new CellValue(HSSFCell.CELL_TYPE_BLANK);
+ break;
+ case HSSFCell.CELL_TYPE_BOOLEAN:
+ retval = new CellValue(HSSFCell.CELL_TYPE_BOOLEAN);
+ retval.setBooleanValue(cell.getBooleanCellValue());
+ break;
+ case HSSFCell.CELL_TYPE_ERROR:
+ retval = new CellValue(HSSFCell.CELL_TYPE_ERROR);
+ retval.setErrorValue(cell.getErrorCellValue());
+ break;
+ case HSSFCell.CELL_TYPE_FORMULA:
+ retval = getCellValueForEval(internalEvaluate(cell, row, sheet, workbook));
+ break;
+ case HSSFCell.CELL_TYPE_NUMERIC:
+ retval = new CellValue(HSSFCell.CELL_TYPE_NUMERIC);
+ retval.setNumberValue(cell.getNumericCellValue());
+ break;
+ case HSSFCell.CELL_TYPE_STRING:
+ retval = new CellValue(HSSFCell.CELL_TYPE_STRING);
+ retval.setStringValue(cell.getStringCellValue());
+ break;
+ }
+ }
+ return retval;
+ }
+
+
+ /**
+ * If cell contains formula, it evaluates the formula, and puts the
+ * formula result back into the cell.
+ * Else if cell does not contain formula, this method leaves the cell
+ * unchanged. Note that the same instance of HSSFCell is returned to
+ * allow chained calls like:
+ * <pre>
+ * int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType();
+ * </pre>
+ * @param cell
+ */
+ public HSSFCell evaluateInCell(HSSFCell cell) {
+ if (cell != null) {
+ switch (cell.getCellType()) {
+ case HSSFCell.CELL_TYPE_FORMULA:
+ CellValue cv = getCellValueForEval(internalEvaluate(cell, row, sheet, workbook));
+ switch (cv.getCellType()) {
+ case HSSFCell.CELL_TYPE_BOOLEAN:
+ cell.setCellValue(cv.getBooleanValue());
+ break;
+ case HSSFCell.CELL_TYPE_ERROR:
+ cell.setCellValue(cv.getErrorValue());
+ break;
+ case HSSFCell.CELL_TYPE_NUMERIC:
+ cell.setCellValue(cv.getNumberValue());
+ break;
+ case HSSFCell.CELL_TYPE_STRING:
+ cell.setCellValue(cv.getStringValue());
+ break;
+ case HSSFCell.CELL_TYPE_BLANK:
+ break;
+ case HSSFCell.CELL_TYPE_FORMULA: // this will never happen, we have already evaluated the formula
+ break;
+ }
+ }
+ }
+ return cell;
+ }
+
+
+ /**
+ * Returns a CellValue wrapper around the supplied ValueEval instance.
+ * @param eval
+ * @return
+ */
+ protected static CellValue getCellValueForEval(ValueEval eval) {
+ CellValue retval = null;
+ if (eval != null) {
+ if (eval instanceof NumberEval) {
+ NumberEval ne = (NumberEval) eval;
+ retval = new CellValue(HSSFCell.CELL_TYPE_NUMERIC);
+ retval.setNumberValue(ne.getNumberValue());
+ }
+ else if (eval instanceof BoolEval) {
+ BoolEval be = (BoolEval) eval;
+ retval = new CellValue(HSSFCell.CELL_TYPE_BOOLEAN);
+ retval.setBooleanValue(be.getBooleanValue());
+ }
+ else if (eval instanceof StringEval) {
+ StringEval ne = (StringEval) eval;
+ retval = new CellValue(HSSFCell.CELL_TYPE_STRING);
+ retval.setStringValue(ne.getStringValue());
+ }
+ else if (eval instanceof BlankEval) {
+ retval = new CellValue(HSSFCell.CELL_TYPE_BLANK);
+ }
+ else {
+ retval = new CellValue(HSSFCell.CELL_TYPE_ERROR);
+ }
+ }
+ return retval;
+ }
+
+ /**
+ * Dev. Note: Internal evaluate must be passed only a formula cell
+ * else a runtime exception will be thrown somewhere inside the method.
+ * (Hence this is a private method.)
+ *
+ * @param formula
+ * @param sheet
+ * @param workbook
+ * @return
+ */
+ protected static ValueEval internalEvaluate(HSSFCell srcCell, HSSFRow srcRow, HSSFSheet sheet, HSSFWorkbook workbook) {
+ int srcRowNum = srcRow.getRowNum();
+ short srcColNum = srcCell.getCellNum();
+
+ FormulaParser parser = new FormulaParser(srcCell.getCellFormula(), workbook.getWorkbook());
+ parser.parse();
+ Ptg[] ptgs = parser.getRPNPtg();
+ // -- parsing over --
+
+
+ Stack stack = new Stack();
+ for (int i = 0, iSize = ptgs.length; i < iSize; i++) {
+
+ // since we dont know how to handle these yet :(
+ if (ptgs[i] instanceof ControlPtg) { continue; }
+ if (ptgs[i] instanceof MemErrPtg) { continue; }
+ if (ptgs[i] instanceof MissingArgPtg) { continue; }
+ if (ptgs[i] instanceof NamePtg) { continue; }
+ if (ptgs[i] instanceof NameXPtg) { continue; }
+ if (ptgs[i] instanceof UnknownPtg) { continue; }
+
+ if (ptgs[i] instanceof OperationPtg) {
+ OperationPtg optg = (OperationPtg) ptgs[i];
+
+ // parens can be ignored since we have RPN tokens
+ if (optg instanceof ParenthesisPtg) { continue; }
+ if (optg instanceof AttrPtg) { continue; }
+ if (optg instanceof UnionPtg) { continue; }
+
+ OperationEval operation = (OperationEval) getOperationEvalForPtg(optg);
+
+ int numops = operation.getNumberOfOperands();
+ Eval[] ops = new Eval[numops];
+
+ // storing the ops in reverse order since they are popping
+ for (int j = numops - 1; j >= 0; j--) {
+ Eval p = (Eval) stack.pop();
+ if (p instanceof ErrorEval) { // fast fail
+ return (ErrorEval) p;
+ }
+ ops[j] = p;
+ }
+ Eval opresult = operation.evaluate(ops, srcRowNum, srcColNum);
+ stack.push(opresult);
+ }
+ else if (ptgs[i] instanceof ReferencePtg) {
+ ReferencePtg ptg = (ReferencePtg) ptgs[i];
+ short colnum = ptg.getColumn();
+ short rownum = ptg.getRow();
+ HSSFRow row = sheet.getRow(rownum);
+ HSSFCell cell = (row != null) ? row.getCell(colnum) : null;
+ pushRef2DEval(ptg, stack, cell, row, sheet, workbook);
+ }
+ else if (ptgs[i] instanceof Ref3DPtg) {
+ Ref3DPtg ptg = (Ref3DPtg) ptgs[i];
+ short colnum = ptg.getColumn();
+ short rownum = ptg.getRow();
+ HSSFSheet xsheet = workbook.getSheetAt(ptg.getExternSheetIndex());
+ HSSFRow row = sheet.getRow(rownum);
+ HSSFCell cell = (row != null) ? row.getCell(colnum) : null;
+ pushRef3DEval(ptg, stack, cell, row, sheet, workbook);
+ }
+ else if (ptgs[i] instanceof AreaPtg) {
+ AreaPtg ap = (AreaPtg) ptgs[i];
+ short row0 = ap.getFirstRow();
+ short col0 = ap.getFirstColumn();
+ short row1 = ap.getLastRow();
+ short col1 = ap.getLastColumn();
+ ValueEval[] values = new ValueEval[(row1 - row0 + 1) * (col1 - col0 + 1)];
+ for (short x = row0; sheet != null && x < row1 + 1; x++) {
+ HSSFRow row = sheet.getRow(x);
+ for (short y = col0; row != null && y < col1 + 1; y++) {
+ values[(x - row0) * (col1 - col0 + 1) + (y - col0)] =
+ getEvalForCell(row.getCell(y), row, sheet, workbook);
+ }
+ }
+ AreaEval ae = new Area2DEval(ap, values);
+ stack.push(ae);
+ }
+ else if (ptgs[i] instanceof Area3DPtg) {
+ Area3DPtg a3dp = (Area3DPtg) ptgs[i];
+ short row0 = a3dp.getFirstRow();
+ short col0 = a3dp.getFirstColumn();
+ short row1 = a3dp.getLastRow();
+ short col1 = a3dp.getLastColumn();
+ HSSFSheet xsheet = workbook.getSheetAt(a3dp.getExternSheetIndex());
+ ValueEval[] values = new ValueEval[(row1 - row0 + 1) * (col1 - col0 + 1)];
+ for (short x = row0; sheet != null && x < row1 + 1; x++) {
+ HSSFRow row = sheet.getRow(x);
+ for (short y = col0; row != null && y < col1 + 1; y++) {
+ values[(x - row0) * (col1 - col0 + 1) + (y - col0)] =
+ getEvalForCell(row.getCell(y), row, sheet, workbook);
+ }
+ }
+ AreaEval ae = new Area3DEval(a3dp, values);
+ stack.push(ae);
+ }
+ else {
+ Eval ptgEval = getEvalForPtg(ptgs[i]);
+ stack.push(ptgEval);
+ }
+ }
+ ValueEval value = ((ValueEval) stack.pop());
+ if (value instanceof RefEval) {
+ RefEval rv = (RefEval) value;
+ value = rv.getInnerValueEval();
+ }
+ else if (value instanceof AreaEval) {
+ AreaEval ae = (AreaEval) value;
+ if (ae.isRow())
+ value = ae.getValueAt(ae.getFirstRow(), srcColNum);
+ else if (ae.isColumn())
+ value = ae.getValueAt(srcRowNum, ae.getFirstColumn());
+ else
+ value = ErrorEval.VALUE_INVALID;
+ }
+ return value;
+ }
+
+ /**
+ * returns the OperationEval concrete impl instance corresponding
+ * to the suplied operationPtg
+ * @param ptg
+ * @return
+ */
+ protected static Eval getOperationEvalForPtg(OperationPtg ptg) {
+ Eval retval = null;
+
+ Class clazz = (Class) OPERATION_EVALS_MAP.get(ptg.getClass());
+ try {
+ Constructor constructor = clazz.getConstructor(OPERATION_CONSTRUCTOR_CLASS_ARRAY);
+ retval = (OperationEval) constructor.newInstance(new Ptg[] { ptg });
+ }
+ catch (Exception e) {
+ throw new RuntimeException("Fatal Error: ", e);
+ }
+ return retval;
+ }
+
+ /**
+ * returns an appropriate Eval impl instance for the Ptg. The Ptg must be
+ * one of: Area3DPtg, AreaPtg, ReferencePtg, Ref3DPtg, IntPtg, NumberPtg,
+ * StringPtg, BoolPtg <br/>special Note: OperationPtg subtypes cannot be
+ * passed here!
+ *
+ * @param ptg
+ * @return
+ */
+ protected static Eval getEvalForPtg(Ptg ptg) {
+ Eval retval = null;
+
+ Class clazz = (Class) VALUE_EVALS_MAP.get(ptg.getClass());
+ try {
+ if (ptg instanceof Area3DPtg) {
+ Constructor constructor = clazz.getConstructor(AREA3D_CONSTRUCTOR_CLASS_ARRAY);
+ retval = (OperationEval) constructor.newInstance(new Ptg[] { ptg });
+ }
+ else if (ptg instanceof AreaPtg) {
+ Constructor constructor = clazz.getConstructor(AREA3D_CONSTRUCTOR_CLASS_ARRAY);
+ retval = (OperationEval) constructor.newInstance(new Ptg[] { ptg });
+ }
+ else if (ptg instanceof ReferencePtg) {
+ Constructor constructor = clazz.getConstructor(REFERENCE_CONSTRUCTOR_CLASS_ARRAY);
+ retval = (OperationEval) constructor.newInstance(new Ptg[] { ptg });
+ }
+ else if (ptg instanceof Ref3DPtg) {
+ Constructor constructor = clazz.getConstructor(REF3D_CONSTRUCTOR_CLASS_ARRAY);
+ retval = (OperationEval) constructor.newInstance(new Ptg[] { ptg });
+ }
+ else {
+ if (ptg instanceof IntPtg || ptg instanceof NumberPtg || ptg instanceof StringPtg
+ || ptg instanceof BoolPtg) {
+ Constructor constructor = clazz.getConstructor(VALUE_CONTRUCTOR_CLASS_ARRAY);
+ retval = (ValueEval) constructor.newInstance(new Ptg[] { ptg });
+ }
+ }
+ }
+ catch (Exception e) {
+ throw new RuntimeException("Fatal Error: ", e);
+ }
+ return retval;
+
+ }
+
+ /**
+ * Given a cell, find its type and from that create an appropriate ValueEval
+ * impl instance and return that. Since the cell could be an external
+ * reference, we need the sheet that this belongs to.
+ * Non existent cells are treated as empty.
+ * @param cell
+ * @param sheet
+ * @param workbook
+ * @return
+ */
+ protected static ValueEval getEvalForCell(HSSFCell cell, HSSFRow row, HSSFSheet sheet, HSSFWorkbook workbook) {
+ ValueEval retval = BlankEval.INSTANCE;
+ if (cell != null) {
+ switch (cell.getCellType()) {
+ case HSSFCell.CELL_TYPE_NUMERIC:
+ retval = new NumberEval(cell.getNumericCellValue());
+ break;
+ case HSSFCell.CELL_TYPE_STRING:
+ retval = new StringEval(cell.getStringCellValue());
+ break;
+ case HSSFCell.CELL_TYPE_FORMULA:
+ retval = (ValueEval) internalEvaluate(cell, row, sheet, workbook);
+ break;
+ case HSSFCell.CELL_TYPE_BOOLEAN:
+ retval = cell.getBooleanCellValue() ? BoolEval.TRUE : BoolEval.FALSE;
+ break;
+ case HSSFCell.CELL_TYPE_BLANK:
+ retval = BlankEval.INSTANCE;
+ break;
+ case HSSFCell.CELL_TYPE_ERROR:
+ retval = ErrorEval.UNKNOWN_ERROR; // TODO: think about this...
+ break;
+ }
+ }
+ return retval;
+ }
+
+ /**
+ * create a Ref2DEval for ReferencePtg and push it on the stack.
+ * Non existent cells are treated as RefEvals containing BlankEval.
+ * @param ptg
+ * @param stack
+ * @param cell
+ * @param sheet
+ * @param workbook
+ */
+ protected static void pushRef2DEval(ReferencePtg ptg, Stack stack,
+ HSSFCell cell, HSSFRow row, HSSFSheet sheet, HSSFWorkbook workbook) {
+ if (cell != null)
+ switch (cell.getCellType()) {
+ case HSSFCell.CELL_TYPE_NUMERIC:
+ stack.push(new Ref2DEval(ptg, new NumberEval(cell.getNumericCellValue()), false));
+ break;
+ case HSSFCell.CELL_TYPE_STRING:
+ stack.push(new Ref2DEval(ptg, new StringEval(cell.getStringCellValue()), false));
+ break;
+ case HSSFCell.CELL_TYPE_FORMULA:
+ stack.push(new Ref2DEval(ptg, internalEvaluate(cell, row, sheet, workbook), true));
+ break;
+ case HSSFCell.CELL_TYPE_BOOLEAN:
+ stack.push(new Ref2DEval(ptg, cell.getBooleanCellValue() ? BoolEval.TRUE : BoolEval.FALSE, false));
+ break;
+ case HSSFCell.CELL_TYPE_BLANK:
+ stack.push(new Ref2DEval(ptg, BlankEval.INSTANCE, false));
+ break;
+ case HSSFCell.CELL_TYPE_ERROR:
+ stack.push(new Ref2DEval(ptg, ErrorEval.UNKNOWN_ERROR, false)); // TODO: think abt this
+ break;
+ }
+ else {
+ stack.push(new Ref2DEval(ptg, BlankEval.INSTANCE, false));
+ }
+ }
+
+ /**
+ * create a Ref3DEval for Ref3DPtg and push it on the stack.
+ *
+ * @param ptg
+ * @param stack
+ * @param cell
+ * @param sheet
+ * @param workbook
+ */
+ protected static void pushRef3DEval(Ref3DPtg ptg, Stack stack, HSSFCell cell,
+ HSSFRow row, HSSFSheet sheet, HSSFWorkbook workbook) {
+ if (cell != null)
+ switch (cell.getCellType()) {
+ case HSSFCell.CELL_TYPE_NUMERIC:
+ stack.push(new Ref3DEval(ptg, new NumberEval(cell.getNumericCellValue()), false));
+ break;
+ case HSSFCell.CELL_TYPE_STRING:
+ stack.push(new Ref3DEval(ptg, new StringEval(cell.getStringCellValue()), false));
+ break;
+ case HSSFCell.CELL_TYPE_FORMULA:
+ stack.push(new Ref3DEval(ptg, internalEvaluate(cell, row, sheet, workbook), true));
+ break;
+ case HSSFCell.CELL_TYPE_BOOLEAN:
+ stack.push(new Ref3DEval(ptg, cell.getBooleanCellValue() ? BoolEval.TRUE : BoolEval.FALSE, false));
+ break;
+ case HSSFCell.CELL_TYPE_BLANK:
+ stack.push(new Ref3DEval(ptg, BlankEval.INSTANCE, false));
+ break;
+ case HSSFCell.CELL_TYPE_ERROR:
+ stack.push(new Ref3DEval(ptg, ErrorEval.UNKNOWN_ERROR, false)); // TODO: think abt this
+ break;
+ }
+ else {
+ stack.push(new Ref3DEval(ptg, BlankEval.INSTANCE, false));
+ }
+ }
+
+ /**
+ * Mimics the 'data view' of a cell. This allows formula evaluator
+ * to return a CellValue instead of precasting the value to String
+ * or Number or boolean type.
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ */
+ public static final class CellValue {
+ private int cellType;
+ private String stringValue;
+ private double numberValue;
+ private boolean booleanValue;
+ private byte errorValue;
+
+ /**
+ * CellType should be one of the types defined in HSSFCell
+ * @param cellType
+ */
+ public CellValue(int cellType) {
+ super();
+ this.cellType = cellType;
+ }
+ /**
+ * @return Returns the booleanValue.
+ */
+ public boolean getBooleanValue() {
+ return booleanValue;
+ }
+ /**
+ * @param booleanValue The booleanValue to set.
+ */
+ public void setBooleanValue(boolean booleanValue) {
+ this.booleanValue = booleanValue;
+ }
+ /**
+ * @return Returns the numberValue.
+ */
+ public double getNumberValue() {
+ return numberValue;
+ }
+ /**
+ * @param numberValue The numberValue to set.
+ */
+ public void setNumberValue(double numberValue) {
+ this.numberValue = numberValue;
+ }
+ /**
+ * @return Returns the stringValue.
+ */
+ public String getStringValue() {
+ return stringValue;
+ }
+ /**
+ * @param stringValue The stringValue to set.
+ */
+ public void setStringValue(String stringValue) {
+ this.stringValue = stringValue;
+ }
+ /**
+ * @return Returns the cellType.
+ */
+ public int getCellType() {
+ return cellType;
+ }
+ /**
+ * @return Returns the errorValue.
+ */
+ public byte getErrorValue() {
+ return errorValue;
+ }
+ /**
+ * @param errorValue The errorValue to set.
+ */
+ public void setErrorValue(byte errorValue) {
+ this.errorValue = errorValue;
+ }
+ }
+
+ /**
+ * Manual testing... needs "the" c:/temp/test1.xls file to be present.
+ *
+ * @param args
+ * @throws Exception
+ */
+ public static void main(String[] args) throws Exception {
+ String FILE_NAME = "c:/temp/test1.xls";
+
+ FileInputStream fis = new FileInputStream(FILE_NAME);
+ HSSFWorkbook wb = new HSSFWorkbook(fis);
+ fis.close();
+ HSSFSheet sheet = wb.getSheetAt(0);
+ HSSFFormulaEvaluator instance = new HSSFFormulaEvaluator(sheet, wb);
+
+ for (int rn = 1, rnSize = 4; rn <= rnSize; rn++) {
+ HSSFRow row = sheet.getRow(rn);
+ for (int cn = 5, cnSize = 7; cn <= cnSize; cn++) {
+ HSSFCell cell = row.getCell((short) cn);
+ System.out.println(new CellReference(rn, cn).toString() + ": " + instance.evaluate(cell));
+ }
+ }
+ }
+
+ /**
+ * debug method
+ *
+ * @param formula
+ * @param sheet
+ * @param workbook
+ */
+ void inspectPtgs(String formula) {
+ FormulaParser fp = new FormulaParser(formula, workbook.getWorkbook());
+ fp.parse();
+ Ptg[] ptgs = fp.getRPNPtg();
+ System.out.println("<ptg-group>");
+ for (int i = 0, iSize = ptgs.length; i < iSize; i++) {
+ System.out.println("<ptg>");
+ System.out.println(ptgs[i]);
+ if (ptgs[i] instanceof OperationPtg) {
+ System.out.println("numoperands: " + ((OperationPtg) ptgs[i]).getNumberOfOperands());
+ }
+ System.out.println("</ptg>");
+ }
+ System.out.println("</ptg-group>");
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 11, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hssf.util.CellReference;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class GenericFormulaTestCase extends TestCase {
+
+ protected static final String FILENAME = System.getProperty("HSSF.testdata.path")+ "/FormulaEvalTestData.xls";
+
+ protected static HSSFWorkbook workbook = null;
+
+ static {
+ try {
+ FileInputStream fin = new FileInputStream( FILENAME );
+ workbook = new HSSFWorkbook( fin );
+ fin.close();
+ }
+ catch (Exception e) {e.printStackTrace();}
+ }
+ protected CellReference beginCell;
+ protected int getBeginRow() {
+ return beginCell.getRow();
+ }
+
+ protected short getBeginCol() {
+ return beginCell.getCol();
+ }
+
+ protected static final HSSFCell getExpectedValueCell(HSSFSheet sheet, HSSFRow row, HSSFCell cell) {
+ HSSFCell retval = null;
+ if (sheet != null) {
+ row = sheet.getRow(row.getRowNum()+1);
+ if (row != null) {
+ retval = row.getCell(cell.getCellNum());
+ }
+ }
+
+ return retval;
+ }
+
+ protected void assertEquals(String msg, HSSFCell expected, HSSFFormulaEvaluator.CellValue actual) {
+ if (expected != null && actual!=null) {
+ if (expected!=null && expected.getCellType() == HSSFCell.CELL_TYPE_STRING) {
+ String value = expected.getStringCellValue();
+ if (value.startsWith("#")) {
+ expected.setCellType(HSSFCell.CELL_TYPE_ERROR);
+ }
+ }
+ if (!(expected == null || actual == null)) {
+ switch (expected.getCellType()) {
+ case HSSFCell.CELL_TYPE_BLANK:
+ assertEquals(msg, HSSFCell.CELL_TYPE_BLANK, actual.getCellType());
+ break;
+ case HSSFCell.CELL_TYPE_BOOLEAN:
+ assertEquals(msg, HSSFCell.CELL_TYPE_BOOLEAN, actual.getCellType());
+ assertEquals(msg, expected.getBooleanCellValue(), actual.getBooleanValue());
+ break;
+ case HSSFCell.CELL_TYPE_ERROR:
+ assertEquals(msg, HSSFCell.CELL_TYPE_ERROR, actual.getCellType()); // TODO: check if exact error matches
+ break;
+ case HSSFCell.CELL_TYPE_FORMULA: // will never be used, since we will call method after formula evaluation
+ throw new AssertionFailedError("Cannot expect formula as result of formula evaluation");
+ case HSSFCell.CELL_TYPE_NUMERIC:
+ assertEquals(msg, HSSFCell.CELL_TYPE_NUMERIC, actual.getCellType());
+ double delta = Math.abs(expected.getNumericCellValue()-actual.getNumberValue());
+ double pctExpected = Math.abs(0.00001*expected.getNumericCellValue());
+ assertTrue(msg, delta <= pctExpected);
+ break;
+ case HSSFCell.CELL_TYPE_STRING:
+ assertEquals(msg, HSSFCell.CELL_TYPE_STRING, actual.getCellType());
+ assertEquals(msg, expected.getStringCellValue(), actual.getStringValue());
+ break;
+ }
+ }
+ else {
+ throw new AssertionFailedError("expected: " + expected + " got:" + actual);
+ }
+ }
+ }
+
+ public GenericFormulaTestCase(String beginCell) {
+ super("genericTest");
+ this.beginCell = new CellReference(beginCell);
+ }
+
+ public void setUp() {
+ }
+
+ public void genericTest() throws Exception {
+ HSSFSheet s = workbook.getSheetAt( 0 );
+ HSSFRow r = s.getRow(getBeginRow());
+ short endcolnum = r.getLastCellNum();
+ HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(s, workbook);
+ evaluator.setCurrentRow(r);
+
+ HSSFCell c = null;
+ for (short colnum=getBeginCol(); colnum < endcolnum; colnum++) {
+ c = r.getCell(colnum);
+ if (c==null || c.getCellType() == HSSFCell.CELL_TYPE_BLANK)
+ continue;
+
+ assertEquals("Sanity check input cell type ", HSSFCell.CELL_TYPE_FORMULA, c.getCellType());
+
+ HSSFFormulaEvaluator.CellValue actualValue = evaluator.evaluate(c);
+
+ HSSFCell expectedValueCell = getExpectedValueCell(s, r, c);
+ assertEquals("Formula: " + c.getCellFormula()
+ + " @ " + getBeginRow() + ":" + colnum,
+ expectedValueCell, actualValue);
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Created on May 11, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.eval;
+
+import junit.framework.TestSuite;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class TestEverything extends TestSuite {
+
+ public static TestSuite suite() {
+ TestSuite suite = new TestSuite("Tests for OperationEval concrete implementation classes.");
+ suite.addTest(new GenericFormulaTestCase("D23"));
+ suite.addTest(new GenericFormulaTestCase("D27"));
+ suite.addTest(new GenericFormulaTestCase("D31"));
+ suite.addTest(new GenericFormulaTestCase("D35"));
+ suite.addTest(new GenericFormulaTestCase("D39"));
+ suite.addTest(new GenericFormulaTestCase("D43"));
+ suite.addTest(new GenericFormulaTestCase("D47"));
+ suite.addTest(new GenericFormulaTestCase("D51"));
+ suite.addTest(new GenericFormulaTestCase("D55"));
+ suite.addTest(new GenericFormulaTestCase("D59"));
+ suite.addTest(new GenericFormulaTestCase("D63"));
+ suite.addTest(new GenericFormulaTestCase("D67"));
+ suite.addTest(new GenericFormulaTestCase("D71"));
+ suite.addTest(new GenericFormulaTestCase("D75"));
+ return suite;
+ }
+}
--- /dev/null
+/*
+ * Created on May 11, 2005
+ *
+ */
+package org.apache.poi.hssf.record.formula.functions;
+
+import org.apache.poi.hssf.record.formula.eval.GenericFormulaTestCase;
+
+import junit.framework.TestSuite;
+
+/**
+ * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
+ *
+ */
+public class TestEverything extends TestSuite {
+
+ public static TestSuite suite() {
+ TestSuite suite = new TestSuite("Tests for individual function classes");
+ String s;
+ for(int i=80; i<1481;i=i+4) {
+ s = "D"+Integer.toString(i).trim();
+ suite.addTest(new GenericFormulaTestCase(s));
+ }
+ return suite;
+ }
+}