From 5766414a695810ac5052cd2fe67f1146571473c6 Mon Sep 17 00:00:00 2001 From: Josh Micich Date: Fri, 19 Jun 2009 22:42:39 +0000 Subject: [PATCH] Added implementation for ISNA() git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@786696 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 9 +-- .../record/formula/eval/FunctionEval.java | 2 +- .../hssf/record/formula/functions/IsNa.java | 56 ++++++++++++++++++ .../poi/hssf/data/FormulaEvalTestData.xls | Bin 157184 -> 157696 bytes 4 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 src/java/org/apache/poi/hssf/record/formula/functions/IsNa.java 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 8bd07c2f341470ddc8d46941c6606ac02770e61e..f91091ad25fbfe466fef472ea217cee427a2bac9 100644 GIT binary patch delta 3443 zcmZWs4OEm>8ouv)zd>dgMo|7lMScVMk>RgF)OCOnNPYveZI6k78Md~O$gWZ=bfR)y zOXQ=umYxo_p0mL2DP^p$qo!zzQrTy%r`#4xE%zW>0`9uIX*v5|hS`4n<~+R5_q^|Y zf9|~u+WNk+^{ladAxz)D=oG*-mjSCWz|hgVPCTnlrlaDLBLply4tL4#s|XH zo5~}WvFK-~OOGc)U2j-#xp;K@gfupLl&tHzVGQB8ddU=~-tsk0ve`xt3sDyt{U)>! zwc5+f$U<2=m14*y7McRTfBn!HWJv~K+3YY*Mto?DnoMCdd6I>xDJE~JaxXJ2{65Pi zQ-~SZ;veP+vef@L?NO5_E&X(HzvfijenV}^nK5&ok1XuZsy5VYXe?PLH4UNw* zGb;#kxpIaV1!UIU)?Pj4f935()up+Ij(;JZ{1(F1lN;CnqOB0vxpH7N4**-b23W%5 zz%rYFy|W2e_fx?7o+1A>U_~9kDg>}=dx72jBQQ%JFzX?*r+^*$1Q>h{?CKR@E50Iq z6xhn^t{t1&jX12kVxC^CfZ0{|+^;#emo&PDwx$A}*H!;*aTwF9W^VgfS=Q=QRLk>L zW!C89T+Ms_H9V)Q*Pq|Z!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