From 0cd7ba4ad251c391b3ba1d41c3a68b95c608106d Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Sat, 29 Mar 2008 22:45:11 +0000 Subject: Few little short/int tweaks, and then tests to show that FormulaEvaluator plays nicely with xssf git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@642634 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/record/formula/functions/Count.java | 97 +++++++++++++++++++++- .../org/apache/poi/hssf/usermodel/HSSFRow.java | 23 ++++- 2 files changed, 115 insertions(+), 5 deletions(-) (limited to 'src/java') 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 736c37c1b7..eb55fc4a42 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 * The cell that is returned is a CELL_TYPE_BLANK. The type can be changed - * either through calling setCellValue or setCellType. + * either through calling setCellValue or setCellType. * * @param column - the column number this cell represents * * @return HSSFCell a high level representation of the created cell. */ + public HSSFCell createCell(int column) + { + short shortCellNum = (short)column; + if(column > 0x7FFF) { + shortCellNum = (short)(0xffff - column); + } + return this.createCell(shortCellNum,HSSFCell.CELL_TYPE_BLANK); + } + /** + * Use this to create new cells within the row and return it. + *

+ * The cell that is returned is a CELL_TYPE_BLANK. The type can be changed + * either through calling setCellValue or setCellType. + * + * @param column - the column number this cell represents + * + * @return HSSFCell a high level representation of the created cell. + */ public HSSFCell createCell(short column, int type) { HSSFCell cell = new HSSFCell(book, sheet, getRowNum(), column, type); -- cgit v1.2.3