git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1898277 13f79535-47bb-0310-9956-ffa450edef68tags/REL_5_2_1
@@ -242,8 +242,49 @@ public final class OperationEvaluationContext { | |||
// no ':' | |||
switch (part1refType) { | |||
case COLUMN: | |||
if (isA1Style) { | |||
return ErrorEval.REF_INVALID; | |||
} else { | |||
try { | |||
String upRef = refStrPart1.toUpperCase(LocaleUtil.getUserLocale()); | |||
int cpos = upRef.indexOf('C'); | |||
String cval = refStrPart1.substring(cpos + 1).trim(); | |||
int absoluteC; | |||
if (cval.startsWith("[") && cval.endsWith("]")) { | |||
int relativeC = Integer.parseInt(cval.substring(1, cval.length() - 1).trim()); | |||
absoluteC = getColumnIndex() + relativeC; | |||
} else if (!cval.isEmpty()) { | |||
absoluteC = Integer.parseInt(cval) - 1; | |||
} else { | |||
return ErrorEval.REF_INVALID; | |||
} | |||
return new LazyAreaEval(0, absoluteC, ssVersion.getLastRowIndex(), absoluteC, sre); | |||
} catch (Exception e) { | |||
return ErrorEval.REF_INVALID; | |||
} | |||
} | |||
case ROW: | |||
return ErrorEval.REF_INVALID; | |||
if (isA1Style) { | |||
return ErrorEval.REF_INVALID; | |||
} else { | |||
try { | |||
String upRef = refStrPart1.toUpperCase(LocaleUtil.getUserLocale()); | |||
int rpos = upRef.indexOf('R'); | |||
String rval = refStrPart1.substring(rpos + 1).trim(); | |||
int absoluteR; | |||
if (rval.startsWith("[") && rval.endsWith("]")) { | |||
int relativeR = Integer.parseInt(rval.substring(1, rval.length() - 1).trim()); | |||
absoluteR = getRowIndex() + relativeR; | |||
} else if (!rval.isEmpty()) { | |||
absoluteR = Integer.parseInt(rval) - 1; | |||
} else { | |||
return ErrorEval.REF_INVALID; | |||
} | |||
return new LazyAreaEval(absoluteR, 0, absoluteR, ssVersion.getLastColumnIndex(), sre); | |||
} catch (Exception e) { | |||
return ErrorEval.REF_INVALID; | |||
} | |||
} | |||
case CELL: | |||
CellReference cr; | |||
if (isA1Style) { |
@@ -169,6 +169,8 @@ final class TestIndirect { | |||
HSSFFormulaEvaluator feA = new HSSFFormulaEvaluator(wbA); | |||
// non-error cases | |||
confirm(feA, c, "INDIRECT(\"R1C1\", FALSE)", 11); | |||
confirm(feA, c, "INDIRECT(\"R1C4\", FALSE)", 14); | |||
confirm(feA, c, "INDIRECT(\"R2C3\", FALSE)", 23); | |||
confirm(feA, c, "INDIRECT(\"r2c3\", FALSE)", 23); | |||
confirm(feA, c, "INDIRECT(\"R[-4]C[0]\", FALSE)", 23); | |||
@@ -179,10 +181,6 @@ final class TestIndirect { | |||
confirm(feA, c, "SUM(INDIRECT(\"Sheet2!r1c2:r3c3\", FALSE))", 351); // area ref | |||
confirm(feA, c, "SUM(INDIRECT(\"Sheet2! R1C2 : R3C3 \", FALSE))", 351); // spaces in area ref | |||
//scenarios yet to support | |||
//R[-4] -- supports getting full row | |||
//C[-4] -- supports getting full column | |||
// simple error propagation: | |||
confirm(feA, c, "INDIRECT(\"'Sheet1 '!R3C4\", FALSE)", ErrorEval.REF_INVALID); | |||
@@ -190,6 +188,26 @@ final class TestIndirect { | |||
} | |||
} | |||
@Test | |||
void testR1C1FullColumn() throws Exception { | |||
try (HSSFWorkbook wbA = createWBA()) { | |||
HSSFCell c = wbA.getSheetAt(0).getRow(0).createCell(20); | |||
HSSFFormulaEvaluator feA = new HSSFFormulaEvaluator(wbA); | |||
confirm(feA, c, "INDIRECT(\"C[-17]\", FALSE)", 14.0); | |||
confirm(feA, c, "INDIRECT(\"C4\", FALSE)", 14.0); | |||
} | |||
} | |||
@Test | |||
void testR1C1FullRow() throws Exception { | |||
try (HSSFWorkbook wbA = createWBA()) { | |||
HSSFCell c = wbA.getSheetAt(0).createRow(100).createCell(0); | |||
HSSFFormulaEvaluator feA = new HSSFFormulaEvaluator(wbA); | |||
confirm(feA, c, "INDIRECT(\"R[-100]\", FALSE)", 11.0); | |||
confirm(feA, c, "INDIRECT(\"R1\", FALSE)", 11.0); | |||
} | |||
} | |||
@Test | |||
void testMultipleWorkbooks() throws Exception { | |||
HSSFWorkbook wbA = createWBA(); |