diff options
author | Cédric Walter <cedricwalter@apache.org> | 2013-08-16 17:35:16 +0000 |
---|---|---|
committer | Cédric Walter <cedricwalter@apache.org> | 2013-08-16 17:35:16 +0000 |
commit | 1d2f94829e8909c704fde1d10aa2bebd5563c005 (patch) | |
tree | 710f3494741985012dc3639f6631f8c5845c3ab2 | |
parent | 1b795e34f794642ebbda58cc256515844146b2bd (diff) | |
download | poi-1d2f94829e8909c704fde1d10aa2bebd5563c005.tar.gz poi-1d2f94829e8909c704fde1d10aa2bebd5563c005.zip |
Bug 54720: Support for Row/Col Area Range like 8:8 or H:H
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1514812 13f79535-47bb-0310-9956-ffa450edef68
4 files changed, 70 insertions, 21 deletions
diff --git a/src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java b/src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java index 87018e6abe..d1407c064b 100644 --- a/src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java +++ b/src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java @@ -37,6 +37,7 @@ import org.apache.poi.ss.util.CellReference.NameType; * For POI internal use only * * @author Josh Micich + * @author Cédric Walter */ public final class OperationEvaluationContext { public static final FreeRefFunction UDF = UserDefinedFunction.instance; @@ -83,13 +84,13 @@ public final class OperationEvaluationContext { } else { // look up sheet by name from external workbook String workbookName = externalSheet.getWorkbookName(); - try {
- targetEvaluator = _bookEvaluator.getOtherWorkbookEvaluator(workbookName);
- } catch (WorkbookNotFoundException e) {
- throw new RuntimeException(e.getMessage(), e);
- }
- otherSheetIndex = targetEvaluator.getSheetIndex(externalSheet.getSheetName());
- if (otherSheetIndex < 0) {
+ try { + targetEvaluator = _bookEvaluator.getOtherWorkbookEvaluator(workbookName); + } catch (WorkbookNotFoundException e) { + throw new RuntimeException(e.getMessage(), e); + } + otherSheetIndex = targetEvaluator.getSheetIndex(externalSheet.getSheetName()); + if (otherSheetIndex < 0) { throw new RuntimeException("Invalid sheet name '" + externalSheet.getSheetName() + "' in bool '" + workbookName + "'."); } @@ -195,16 +196,32 @@ public final class OperationEvaluationContext { int firstRow, firstCol, lastRow, lastCol; switch (part1refType) { case COLUMN: - firstRow =0; - lastRow = ssVersion.getLastRowIndex(); - firstCol = parseColRef(refStrPart1); - lastCol = parseColRef(refStrPart2); - break; + firstRow =0; + if (part2refType.equals(NameType.COLUMN)) + { + lastRow = ssVersion.getLastRowIndex(); + firstCol = parseRowRef(refStrPart1); + lastCol = parseRowRef(refStrPart2); + } + else { + lastRow = ssVersion.getLastRowIndex(); + firstCol = parseColRef(refStrPart1); + lastCol = parseColRef(refStrPart2); + } + break; case ROW: - firstCol = 0; - lastCol = ssVersion.getLastColumnIndex(); - firstRow = parseRowRef(refStrPart1); - lastRow = parseRowRef(refStrPart2); + // support of cell range in the form of integer:integer + firstCol = 0; + if (part2refType.equals(NameType.ROW)) + { + firstRow = parseColRef(refStrPart1); + lastRow = parseColRef(refStrPart2); + lastCol = ssVersion.getLastColumnIndex(); + } else { + lastCol = ssVersion.getLastColumnIndex(); + firstRow = parseRowRef(refStrPart1); + lastRow = parseRowRef(refStrPart2); + } break; case CELL: CellReference cr; diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestIndirectFunctionFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestIndirectFunctionFromSpreadsheet.java new file mode 100644 index 0000000000..b777dca8a7 --- /dev/null +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestIndirectFunctionFromSpreadsheet.java @@ -0,0 +1,35 @@ +/* ====================================================================
+ 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.ss.formula.functions;
+
+/**
+ * Tests INDIRECT() as loaded from a test data spreadsheet.<p/>
+ *
+ * Tests for bug fixes and specific/tricky behaviour can be found in the corresponding test class
+ * (<tt>TestXxxx</tt>) of the target (<tt>Xxxx</tt>) implementor, where execution can be observed
+ * more easily.
+ *
+ * @author Cédric Walter
+ */
+public final class TestIndirectFunctionFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
+
+ @Override
+ protected String getFilename() {
+ return "IndirectFunctionTestCaseData.xls";
+ }
+}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestMatchFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestMatchFunctionsFromSpreadsheet.java index 7fcb1fa13b..29aeec8d1e 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestMatchFunctionsFromSpreadsheet.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestMatchFunctionsFromSpreadsheet.java @@ -20,16 +20,13 @@ package org.apache.poi.ss.formula.functions; /**
- * Tests lookup functions (VLOOKUP, HLOOKUP, LOOKUP, MATCH) as loaded from a test data spreadsheet.<p/>
- * These tests have been separated from the common function and operator tests because the lookup
- * functions have more complex test cases and test data setup.
+ * Tests Match functions as loaded from a test data spreadsheet.<p/>
*
* Tests for bug fixes and specific/tricky behaviour can be found in the corresponding test class
* (<tt>TestXxxx</tt>) of the target (<tt>Xxxx</tt>) implementor, where execution can be observed
* more easily.
*
- * @author Josh Micich
- * @author Cedric Walter at innoveo.com
+ * @author Cédric Walter
*/
public final class TestMatchFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
diff --git a/test-data/spreadsheet/IndirectFunctionTestCaseData.xls b/test-data/spreadsheet/IndirectFunctionTestCaseData.xls Binary files differnew file mode 100644 index 0000000000..c7f7173ec8 --- /dev/null +++ b/test-data/spreadsheet/IndirectFunctionTestCaseData.xls |