]> source.dussan.org Git - poi.git/commitdiff
bug 58339: patch from Patrick Zimmermann to allow OFFSET() to accept missing optional...
authorJaven O'Neal <onealj@apache.org>
Mon, 15 Feb 2016 20:27:59 +0000 (20:27 +0000)
committerJaven O'Neal <onealj@apache.org>
Mon, 15 Feb 2016 20:27:59 +0000 (20:27 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1730606 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/formula/functions/Offset.java
test-data/spreadsheet/FormulaEvalTestData.xls
test-data/spreadsheet/FormulaEvalTestData_Copy.xlsx

index d9f240d67e3beed7ab9a3ba1ee1a5bf911b05a33..cffa26a4c4c6a5bf5267518e293333c37f6230e5 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.poi.ss.formula.functions;
 import org.apache.poi.ss.formula.eval.AreaEval;
 import org.apache.poi.ss.formula.eval.ErrorEval;
 import org.apache.poi.ss.formula.eval.EvaluationException;
+import org.apache.poi.ss.formula.eval.MissingArgEval;
 import org.apache.poi.ss.formula.eval.OperandResolver;
 import org.apache.poi.ss.formula.eval.RefEval;
 import org.apache.poi.ss.formula.eval.ValueEval;
@@ -171,11 +172,17 @@ public final class Offset implements Function {
                        int columnOffset = evaluateIntArg(args[2], srcCellRow, srcCellCol);
                        int height = baseRef.getHeight();
                        int width = baseRef.getWidth();
+                       // optional arguments
+                       // If height or width is omitted, it is assumed to be the same height or width as reference.
                        switch(args.length) {
                                case 5:
-                                       width = evaluateIntArg(args[4], srcCellRow, srcCellCol);
+                                       if(!(args[4] instanceof MissingArgEval)) {
+                                               width = evaluateIntArg(args[4], srcCellRow, srcCellCol);
+                                       }
                                case 4:
-                                       height = evaluateIntArg(args[3], srcCellRow, srcCellCol);
+                                       if(!(args[3] instanceof MissingArgEval)) {
+                                               height = evaluateIntArg(args[3], srcCellRow, srcCellCol);
+                                       }
                        }
                        // Zero height or width raises #REF! error
                        if(height == 0 || width == 0) {
index 61465244b5d17a38c89f1128f78b7481c23aba90..b9165649c1330bca9e39e3dcbf9a8f13b742ec65 100644 (file)
Binary files a/test-data/spreadsheet/FormulaEvalTestData.xls and b/test-data/spreadsheet/FormulaEvalTestData.xls differ
index 3d70eba69159b3fc7467bd66f574cf370f2474b0..d9dfac62b2c9c8f1426c5800189ed19e60f93edc 100644 (file)
Binary files a/test-data/spreadsheet/FormulaEvalTestData_Copy.xlsx and b/test-data/spreadsheet/FormulaEvalTestData_Copy.xlsx differ