From a727830c61de0a7f99b811347b942684dabf830f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Walter?= Date: Fri, 16 Aug 2013 17:35:16 +0000 Subject: [PATCH] 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 --- .../formula/OperationEvaluationContext.java | 49 ++++++++++++------ .../TestIndirectFunctionFromSpreadsheet.java | 35 +++++++++++++ .../TestMatchFunctionsFromSpreadsheet.java | 7 +-- .../IndirectFunctionTestCaseData.xls | Bin 0 -> 38912 bytes 4 files changed, 70 insertions(+), 21 deletions(-) create mode 100644 src/testcases/org/apache/poi/ss/formula/functions/TestIndirectFunctionFromSpreadsheet.java create mode 100644 test-data/spreadsheet/IndirectFunctionTestCaseData.xls diff --git a/src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java b/src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java index 87018e6ab..d1407c064 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 000000000..b777dca8a --- /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.

+ * + * Tests for bug fixes and specific/tricky behaviour can be found in the corresponding test class + * (TestXxxx) of the target (Xxxx) 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 7fcb1fa13..29aeec8d1 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.

- * 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.

* * Tests for bug fixes and specific/tricky behaviour can be found in the corresponding test class * (TestXxxx) of the target (Xxxx) 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 new file mode 100644 index 0000000000000000000000000000000000000000..c7f7173ec8de6b3f192148da24d9b61bfdd58485 GIT binary patch literal 38912 zcmeHw3wT`Bb?%xl%j=5Hs`0OgPWMiMCXK#|2oVzl;|lE0gBiDD@HXTmMMR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