From 4451a53ad367ec8977e6ff1838605386326b283d Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Sun, 30 Mar 2008 13:39:51 +0000 Subject: [PATCH] Count implementation from ooxml branch git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@642737 13f79535-47bb-0310-9956-ffa450edef68 --- .../hssf/record/formula/functions/Count.java | 97 ++++++++++++++++++- 1 file changed, 95 insertions(+), 2 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Count.java b/src/java/org/apache/poi/hssf/record/formula/functions/Count.java index 736c37c1b..eb55fc4a4 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Count.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Count.java @@ -20,6 +20,99 @@ */ package org.apache.poi.hssf.record.formula.functions; -public class Count extends NotImplementedFunction { +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.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.RefEval; +import org.apache.poi.hssf.record.formula.eval.ValueEval; -} +/** + * Counts the number of cells that contain numeric data within + * the list of arguments. + * + * Excel Syntax + * COUNT(value1,value2,...) + * Value1, value2, ... are 1 to 30 arguments representing the values or ranges to be counted. + * + * TODO: Check this properly matches excel on edge cases + * like formula cells, error cells etc + */ +public class Count implements Function { + + public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + int nArgs = args.length; + if (nArgs < 1) { + // too few arguments + return ErrorEval.VALUE_INVALID; + } + + if (nArgs > 30) { + // too many arguments + return ErrorEval.VALUE_INVALID; + } + + int temp = 0; + + for(int i=0; i