From: Josh Micich Date: Fri, 19 Jun 2009 22:42:39 +0000 (+0000) Subject: Added implementation for ISNA() X-Git-Tag: REL_3_5-FINAL~96 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5766414a695810ac5052cd2fe67f1146571473c6;p=poi.git Added implementation for ISNA() git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@786696 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 2357a17095..9e8e2a6a3b 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -33,6 +33,7 @@ + Added implementation for ISNA() 46793 - fixed SimpleShape#getLineWidth to handle default line width 47356 - removed unused private fields in HWPF BorderCode 47355 - Improved HWPF TableCell to expose TableCellDescriptor @@ -319,7 +320,7 @@ 44937 - Partial support for extracting Escher images from HWPF files 44824 - Avoid an infinite loop when reading some HWPF pictures 44898 - Correctly handle short last blocks in POIFS - + 44306 - fixed reading/writing of AttrPtg(type=choose) and method toFormulaString() for CHOOSE formulas 24207 - added HSSFName.isDeleted() to check if the name points to cell that no longer exists @@ -523,14 +524,14 @@ Image writing support HSLF - Initial PowerPoint Support. Includes: Support for text extraction across the whole file; Support for getting individual slides, and their notes, and extracting text from those; Initial support for changing (but not adding) text - + Outlining support 27574 - [PATCH] HSSFDateUtil.getExcelDate() is one hour off when DST changes 26465 - [PATCH] wrong lastrow entry 28203 - [PATCH] Unable to open read-write excel file including forms - + Add support for the Escher file format 27005 java.lang.IndexOutOfBoundsException during Workbook.cloneSheet() @@ -539,7 +540,7 @@ No changes - + Bug 25695 - HSSFCell.getStringCellValue() on cell which has string formula will return swap bye unicode characters. Updated website for upcoming release diff --git a/src/java/org/apache/poi/hssf/record/formula/eval/FunctionEval.java b/src/java/org/apache/poi/hssf/record/formula/eval/FunctionEval.java index ef7f39a6b0..3b74cc9a95 100644 --- a/src/java/org/apache/poi/hssf/record/formula/eval/FunctionEval.java +++ b/src/java/org/apache/poi/hssf/record/formula/eval/FunctionEval.java @@ -26,7 +26,6 @@ import org.apache.poi.hssf.record.formula.functions.*; /** * @author Amol S. Deshmukh < amolweb at ya hoo dot com > - * */ public abstract class FunctionEval implements OperationEval { /** @@ -79,6 +78,7 @@ public abstract class FunctionEval implements OperationEval { retval[0] = new Count(); retval[1] = new If(); + retval[2] = new IsNa(); retval[3] = new IsError(); retval[ID.SUM] = AggregateFunction.SUM; diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/IsNa.java b/src/java/org/apache/poi/hssf/record/formula/functions/IsNa.java new file mode 100644 index 0000000000..0c9cf4f200 --- /dev/null +++ b/src/java/org/apache/poi/hssf/record/formula/functions/IsNa.java @@ -0,0 +1,56 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +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.EvaluationException; +import org.apache.poi.hssf.record.formula.eval.OperandResolver; +import org.apache.poi.ss.usermodel.ErrorConstants; + +/** + * Implementation for Excel ISNA() function.

+ * + * Syntax:
+ * ISNA(value)

+ * + * value The value to be tested
+ *
+ * Returns TRUE if the specified value is '#N/A', FALSE otherwise. + * + * @author Josh Micich + */ +public final class IsNa implements Function { + + public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + if(args.length != 1) { + return ErrorEval.VALUE_INVALID; + } + Eval arg = args[0]; + + try { + OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol); + } catch (EvaluationException e) { + if (e.getErrorEval().getErrorCode() == ErrorConstants.ERROR_NA) { + return BoolEval.TRUE; + } + } + return BoolEval.FALSE; + } +} diff --git a/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls b/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls index 8bd07c2f34..f91091ad25 100644 Binary files a/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls and b/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls differ