package org.apache.poi.ss.formula;
-import org.apache.poi.ss.formula.ptg.AreaI;
-import org.apache.poi.ss.formula.ptg.AreaI.OffsetArea;
import org.apache.poi.ss.formula.eval.AreaEval;
import org.apache.poi.ss.formula.eval.AreaEvalBase;
import org.apache.poi.ss.formula.eval.ValueEval;
+import org.apache.poi.ss.formula.ptg.AreaI;
+import org.apache.poi.ss.formula.ptg.AreaI.OffsetArea;
import org.apache.poi.ss.util.CellReference;
/**
- *
- * @author Josh Micich
+ * Provides Lazy Evaluation to a 3D Ranges
+ *
+ * TODO Provide access to multiple sheets where present
*/
final class LazyAreaEval extends AreaEvalBase {
+ private final SheetRangeEvaluator _evaluator;
- private final SheetRefEvaluator _evaluator;
-
- LazyAreaEval(AreaI ptg, SheetRefEvaluator evaluator) {
+ LazyAreaEval(AreaI ptg, SheetRangeEvaluator evaluator) {
super(ptg);
_evaluator = evaluator;
}
public LazyAreaEval(int firstRowIndex, int firstColumnIndex, int lastRowIndex,
- int lastColumnIndex, SheetRefEvaluator evaluator) {
+ int lastColumnIndex, SheetRangeEvaluator evaluator) {
super(firstRowIndex, firstColumnIndex, lastRowIndex, lastColumnIndex);
_evaluator = evaluator;
}
int rowIx = (relativeRowIndex + getFirstRow() ) ;
int colIx = (relativeColumnIndex + getFirstColumn() ) ;
- return _evaluator.getEvalForCell(rowIx, colIx);
+ return _evaluator.getEvalForCell(_evaluator.getFirstSheetIndex(), rowIx, colIx);
}
public AreaEval offset(int relFirstRowIx, int relLastRowIx, int relFirstColIx, int relLastColIx) {
CellReference crB = new CellReference(getLastRow(), getLastColumn());
StringBuffer sb = new StringBuffer();
sb.append(getClass().getName()).append("[");
- sb.append(_evaluator.getSheetName());
+ sb.append(_evaluator.getSheetNameRange());
sb.append('!');
sb.append(crA.formatAsString());
sb.append(':');
*/
public boolean isSubTotal(int rowIndex, int columnIndex){
// delegate the query to the sheet evaluator which has access to internal ptgs
- return _evaluator.isSubTotal(getFirstRow() + rowIndex, getFirstColumn() + columnIndex);
+ SheetRefEvaluator _sre = _evaluator.getSheetEvaluator(_evaluator.getFirstSheetIndex());
+ return _sre.isSubTotal(getFirstRow() + rowIndex, getFirstColumn() + columnIndex);
}
}
package org.apache.poi.ss.formula;
-import org.apache.poi.ss.formula.ptg.AreaI;
-import org.apache.poi.ss.formula.ptg.AreaI.OffsetArea;
import org.apache.poi.ss.formula.eval.AreaEval;
import org.apache.poi.ss.formula.eval.RefEvalBase;
import org.apache.poi.ss.formula.eval.ValueEval;
+import org.apache.poi.ss.formula.ptg.AreaI;
+import org.apache.poi.ss.formula.ptg.AreaI.OffsetArea;
import org.apache.poi.ss.util.CellReference;
/**
-*
-* @author Josh Micich
-*/
+ * Provides Lazy Evaluation to a 3D Reference
+ *
+ * TODO Provide access to multiple sheets where present
+ */
final class LazyRefEval extends RefEvalBase {
+ private final SheetRangeEvaluator _evaluator;
- private final SheetRefEvaluator _evaluator;
-
- public LazyRefEval(int rowIndex, int columnIndex, SheetRefEvaluator sre) {
+ public LazyRefEval(int rowIndex, int columnIndex, SheetRangeEvaluator sre) {
super(rowIndex, columnIndex);
if (sre == null) {
throw new IllegalArgumentException("sre must not be null");
}
public ValueEval getInnerValueEval() {
- return _evaluator.getEvalForCell(getRow(), getColumn());
+ return _evaluator.getEvalForCell(_evaluator.getFirstSheetIndex(), getRow(), getColumn());
}
public AreaEval offset(int relFirstRowIx, int relLastRowIx, int relFirstColIx, int relLastColIx) {
CellReference cr = new CellReference(getRow(), getColumn());
StringBuffer sb = new StringBuffer();
sb.append(getClass().getName()).append("[");
- sb.append(_evaluator.getSheetName());
+ sb.append(_evaluator.getSheetNameRange());
sb.append('!');
sb.append(cr.formatAsString());
sb.append("]");
import org.apache.poi.ss.formula.CollaboratingWorkbooksEnvironment.WorkbookNotFoundException;
import org.apache.poi.ss.formula.EvaluationWorkbook.ExternalName;
import org.apache.poi.ss.formula.EvaluationWorkbook.ExternalSheet;
+import org.apache.poi.ss.formula.EvaluationWorkbook.ExternalSheetRange;
import org.apache.poi.ss.formula.eval.AreaEval;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.ExternalNameEval;
return _columnIndex;
}
- SheetRefEvaluator createExternSheetRefEvaluator(ExternSheetReferenceToken ptg) {
+ SheetRangeEvaluator createExternSheetRefEvaluator(ExternSheetReferenceToken ptg) {
return createExternSheetRefEvaluator(ptg.getExternSheetIndex());
}
- SheetRefEvaluator createExternSheetRefEvaluator(String sheetName, int externalWorkbookNumber) {
+ SheetRangeEvaluator createExternSheetRefEvaluator(String sheetName, int externalWorkbookNumber) {
ExternalSheet externalSheet = _workbook.getExternalSheet(sheetName, null, externalWorkbookNumber);
return createExternSheetRefEvaluator(externalSheet);
}
- SheetRefEvaluator createExternSheetRefEvaluator(int externSheetIndex) {
+ SheetRangeEvaluator createExternSheetRefEvaluator(int externSheetIndex) {
ExternalSheet externalSheet = _workbook.getExternalSheet(externSheetIndex);
return createExternSheetRefEvaluator(externalSheet);
}
- SheetRefEvaluator createExternSheetRefEvaluator(ExternalSheet externalSheet) {
+ SheetRangeEvaluator createExternSheetRefEvaluator(ExternalSheet externalSheet) {
WorkbookEvaluator targetEvaluator;
- int otherSheetIndex;
+ int otherFirstSheetIndex;
+ int otherLastSheetIndex = -1;
if (externalSheet == null || externalSheet.getWorkbookName() == null) {
// sheet is in same workbook
- otherSheetIndex = _workbook.getSheetIndex(externalSheet.getSheetName());
targetEvaluator = _bookEvaluator;
+ otherFirstSheetIndex = _workbook.getSheetIndex(externalSheet.getSheetName());
+
+ if (externalSheet instanceof ExternalSheetRange) {
+ String lastSheetName = ((ExternalSheetRange)externalSheet).getLastSheetName();
+ otherLastSheetIndex = _workbook.getSheetIndex(lastSheetName);
+ }
} else {
// look up sheet by name from external workbook
String workbookName = externalSheet.getWorkbookName();
} catch (WorkbookNotFoundException e) {
throw new RuntimeException(e.getMessage(), e);
}
- otherSheetIndex = targetEvaluator.getSheetIndex(externalSheet.getSheetName());
- if (otherSheetIndex < 0) {
+
+ otherFirstSheetIndex = targetEvaluator.getSheetIndex(externalSheet.getSheetName());
+ if (externalSheet instanceof ExternalSheetRange) {
+ String lastSheetName = ((ExternalSheetRange)externalSheet).getLastSheetName();
+ otherLastSheetIndex = targetEvaluator.getSheetIndex(lastSheetName);
+ }
+
+ if (otherFirstSheetIndex < 0) {
throw new RuntimeException("Invalid sheet name '" + externalSheet.getSheetName()
+ "' in bool '" + workbookName + "'.");
}
}
- return new SheetRefEvaluator(targetEvaluator, _tracker, otherSheetIndex);
+
+ if (otherLastSheetIndex == -1) {
+ // Reference to just one sheet
+ otherLastSheetIndex = otherFirstSheetIndex;
+ }
+
+ SheetRefEvaluator[] evals = new SheetRefEvaluator[otherLastSheetIndex-otherFirstSheetIndex+1];
+ for (int i=0; i<evals.length; i++) {
+ int otherSheetIndex = i+otherFirstSheetIndex;
+ evals[i] = new SheetRefEvaluator(targetEvaluator, _tracker, otherSheetIndex);
+ }
+ return new SheetRangeEvaluator(otherFirstSheetIndex, otherLastSheetIndex, evals);
}
/**
return new SheetRefEvaluator(targetEvaluator, _tracker, otherSheetIndex);
}
- public SheetRefEvaluator getRefEvaluatorForCurrentSheet() {
- return new SheetRefEvaluator(_bookEvaluator, _tracker, _sheetIndex);
+ public SheetRangeEvaluator getRefEvaluatorForCurrentSheet() {
+ SheetRefEvaluator sre = new SheetRefEvaluator(_bookEvaluator, _tracker, _sheetIndex);
+ return new SheetRangeEvaluator(_sheetIndex, sre);
}
if (!isA1Style) {
throw new RuntimeException("R1C1 style not supported yet");
}
- SheetRefEvaluator sre = createExternSheetRefEvaluator(workbookName, sheetName);
- if (sre == null) {
+ SheetRefEvaluator se = createExternSheetRefEvaluator(workbookName, sheetName);
+ if (se == null) {
return ErrorEval.REF_INVALID;
}
+ SheetRangeEvaluator sre = new SheetRangeEvaluator(_sheetIndex, se);
+
// ugly typecast - TODO - make spreadsheet version more easily accessible
SpreadsheetVersion ssVersion = ((FormulaParsingWorkbook)_workbook).getSpreadsheetVersion();
}
public ValueEval getRefEval(int rowIndex, int columnIndex) {
- SheetRefEvaluator sre = getRefEvaluatorForCurrentSheet();
+ SheetRangeEvaluator sre = getRefEvaluatorForCurrentSheet();
return new LazyRefEval(rowIndex, columnIndex, sre);
}
public ValueEval getRef3DEval(Ref3DPtg rptg) {
- SheetRefEvaluator sre = createExternSheetRefEvaluator(rptg.getExternSheetIndex());
+ SheetRangeEvaluator sre = createExternSheetRefEvaluator(rptg.getExternSheetIndex());
return new LazyRefEval(rptg.getRow(), rptg.getColumn(), sre);
}
public ValueEval getRef3DEval(Ref3DPxg rptg) {
- SheetRefEvaluator sre = createExternSheetRefEvaluator(rptg.getSheetName(), rptg.getExternalWorkbookNumber());
+ SheetRangeEvaluator sre = createExternSheetRefEvaluator(rptg.getSheetName(), rptg.getExternalWorkbookNumber());
return new LazyRefEval(rptg.getRow(), rptg.getColumn(), sre);
}
public ValueEval getAreaEval(int firstRowIndex, int firstColumnIndex,
int lastRowIndex, int lastColumnIndex) {
- SheetRefEvaluator sre = getRefEvaluatorForCurrentSheet();
+ SheetRangeEvaluator sre = getRefEvaluatorForCurrentSheet();
return new LazyAreaEval(firstRowIndex, firstColumnIndex, lastRowIndex, lastColumnIndex, sre);
}
public ValueEval getArea3DEval(Area3DPtg aptg) {
- SheetRefEvaluator sre = createExternSheetRefEvaluator(aptg.getExternSheetIndex());
+ SheetRangeEvaluator sre = createExternSheetRefEvaluator(aptg.getExternSheetIndex());
return new LazyAreaEval(aptg.getFirstRow(), aptg.getFirstColumn(),
aptg.getLastRow(), aptg.getLastColumn(), sre);
}
public ValueEval getArea3DEval(Area3DPxg aptg) {
- SheetRefEvaluator sre = createExternSheetRefEvaluator(aptg.getSheetName(), aptg.getExternalWorkbookNumber());
+ SheetRangeEvaluator sre = createExternSheetRefEvaluator(aptg.getSheetName(), aptg.getExternalWorkbookNumber());
return new LazyAreaEval(aptg.getFirstRow(), aptg.getFirstColumn(),
aptg.getLastRow(), aptg.getLastColumn(), sre);
}