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
This commit is contained in:
Cédric Walter 2013-08-16 17:35:16 +00:00
parent baee918c5a
commit a727830c61
4 changed files with 70 additions and 21 deletions

View File

@ -37,6 +37,7 @@ import org.apache.poi.ss.util.CellReference.NameType;
* For POI internal use only * For POI internal use only
* *
* @author Josh Micich * @author Josh Micich
* @author Cédric Walter
*/ */
public final class OperationEvaluationContext { public final class OperationEvaluationContext {
public static final FreeRefFunction UDF = UserDefinedFunction.instance; public static final FreeRefFunction UDF = UserDefinedFunction.instance;
@ -83,13 +84,13 @@ public final class OperationEvaluationContext {
} else { } else {
// look up sheet by name from external workbook // look up sheet by name from external workbook
String workbookName = externalSheet.getWorkbookName(); String workbookName = externalSheet.getWorkbookName();
try { try {
targetEvaluator = _bookEvaluator.getOtherWorkbookEvaluator(workbookName); targetEvaluator = _bookEvaluator.getOtherWorkbookEvaluator(workbookName);
} catch (WorkbookNotFoundException e) { } catch (WorkbookNotFoundException e) {
throw new RuntimeException(e.getMessage(), e); throw new RuntimeException(e.getMessage(), e);
} }
otherSheetIndex = targetEvaluator.getSheetIndex(externalSheet.getSheetName()); otherSheetIndex = targetEvaluator.getSheetIndex(externalSheet.getSheetName());
if (otherSheetIndex < 0) { if (otherSheetIndex < 0) {
throw new RuntimeException("Invalid sheet name '" + externalSheet.getSheetName() throw new RuntimeException("Invalid sheet name '" + externalSheet.getSheetName()
+ "' in bool '" + workbookName + "'."); + "' in bool '" + workbookName + "'.");
} }
@ -195,16 +196,32 @@ public final class OperationEvaluationContext {
int firstRow, firstCol, lastRow, lastCol; int firstRow, firstCol, lastRow, lastCol;
switch (part1refType) { switch (part1refType) {
case COLUMN: case COLUMN:
firstRow =0; firstRow =0;
lastRow = ssVersion.getLastRowIndex(); if (part2refType.equals(NameType.COLUMN))
firstCol = parseColRef(refStrPart1); {
lastCol = parseColRef(refStrPart2); lastRow = ssVersion.getLastRowIndex();
break; firstCol = parseRowRef(refStrPart1);
lastCol = parseRowRef(refStrPart2);
}
else {
lastRow = ssVersion.getLastRowIndex();
firstCol = parseColRef(refStrPart1);
lastCol = parseColRef(refStrPart2);
}
break;
case ROW: case ROW:
firstCol = 0; // support of cell range in the form of integer:integer
lastCol = ssVersion.getLastColumnIndex(); firstCol = 0;
firstRow = parseRowRef(refStrPart1); if (part2refType.equals(NameType.ROW))
lastRow = parseRowRef(refStrPart2); {
firstRow = parseColRef(refStrPart1);
lastRow = parseColRef(refStrPart2);
lastCol = ssVersion.getLastColumnIndex();
} else {
lastCol = ssVersion.getLastColumnIndex();
firstRow = parseRowRef(refStrPart1);
lastRow = parseRowRef(refStrPart2);
}
break; break;
case CELL: case CELL:
CellReference cr; CellReference cr;

View File

@ -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";
}
}

View File

@ -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/> * Tests Match functions 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 for bug fixes and specific/tricky behaviour can be found in the corresponding test class * 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 * (<tt>TestXxxx</tt>) of the target (<tt>Xxxx</tt>) implementor, where execution can be observed
* more easily. * more easily.
* *
* @author Josh Micich * @author Cédric Walter
* @author Cedric Walter at innoveo.com
*/ */
public final class TestMatchFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet { public final class TestMatchFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {

Binary file not shown.