// 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) {
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);
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);
}
}
+ @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();