use of org.apache.poi.ss.util.CellReference in project poi by apache.
the class WorkbookEvaluator method evaluateAny.
/**
* @return never <code>null</code>, never {@link BlankEval}
*/
private ValueEval evaluateAny(EvaluationCell srcCell, int sheetIndex, int rowIndex, int columnIndex, EvaluationTracker tracker) {
// avoid tracking dependencies to cells that have constant definition
boolean shouldCellDependencyBeRecorded = _stabilityClassifier == null ? true : !_stabilityClassifier.isCellFinal(sheetIndex, rowIndex, columnIndex);
if (srcCell == null || srcCell.getCellTypeEnum() != CellType.FORMULA) {
ValueEval result = getValueFromNonFormulaCell(srcCell);
if (shouldCellDependencyBeRecorded) {
tracker.acceptPlainValueDependency(_workbookIx, sheetIndex, rowIndex, columnIndex, result);
}
return result;
}
FormulaCellCacheEntry cce = _cache.getOrCreateFormulaCellEntry(srcCell);
if (shouldCellDependencyBeRecorded || cce.isInputSensitive()) {
tracker.acceptFormulaDependency(cce);
}
IEvaluationListener evalListener = _evaluationListener;
ValueEval result;
if (cce.getValue() == null) {
if (!tracker.startEvaluate(cce)) {
return ErrorEval.CIRCULAR_REF_ERROR;
}
OperationEvaluationContext ec = new OperationEvaluationContext(this, _workbook, sheetIndex, rowIndex, columnIndex, tracker);
try {
Ptg[] ptgs = _workbook.getFormulaTokens(srcCell);
if (evalListener == null) {
result = evaluateFormula(ec, ptgs);
} else {
evalListener.onStartEvaluate(srcCell, cce);
result = evaluateFormula(ec, ptgs);
evalListener.onEndEvaluate(cce, result);
}
tracker.updateCacheResult(result);
} catch (NotImplementedException e) {
throw addExceptionInfo(e, sheetIndex, rowIndex, columnIndex);
} catch (RuntimeException re) {
if (re.getCause() instanceof WorkbookNotFoundException && _ignoreMissingWorkbooks) {
logInfo(re.getCause().getMessage() + " - Continuing with cached value!");
switch(srcCell.getCachedFormulaResultTypeEnum()) {
case NUMERIC:
result = new NumberEval(srcCell.getNumericCellValue());
break;
case STRING:
result = new StringEval(srcCell.getStringCellValue());
break;
case BLANK:
result = BlankEval.instance;
break;
case BOOLEAN:
result = BoolEval.valueOf(srcCell.getBooleanCellValue());
break;
case ERROR:
result = ErrorEval.valueOf(srcCell.getErrorCellValue());
break;
case FORMULA:
default:
throw new RuntimeException("Unexpected cell type '" + srcCell.getCellTypeEnum() + "' found!");
}
} else {
throw re;
}
} finally {
tracker.endEvaluate(cce);
}
} else {
if (evalListener != null) {
evalListener.onCacheHit(sheetIndex, rowIndex, columnIndex, cce.getValue());
}
return cce.getValue();
}
if (isDebugLogEnabled()) {
String sheetName = getSheetName(sheetIndex);
CellReference cr = new CellReference(rowIndex, columnIndex);
logDebug("Evaluated " + sheetName + "!" + cr.formatAsString() + " to " + result);
}
// the top evaluation frame
return result;
}
use of org.apache.poi.ss.util.CellReference in project poi by apache.
the class XSSFTable method getRowCount.
/**
* @return the total number of rows in the selection. (Note: in this version autofiltering is ignored)
* Returns <code>0</code> if the start or end cell references are not set.
*
* Does not track updates to underlying changes to CTTable
* To synchronize with changes to the underlying CTTable,
* call {@link #updateReferences()}.
*/
public int getRowCount() {
CellReference from = getStartCellReference();
CellReference to = getEndCellReference();
int rowCount = 0;
if (from != null && to != null) {
rowCount = to.getRow() - from.getRow() + 1;
}
return rowCount;
}
use of org.apache.poi.ss.util.CellReference in project poi by apache.
the class XSSFTable method setCellReferences.
/**
* @since POI 3.15 beta 3
*/
private void setCellReferences() {
String ref = ctTable.getRef();
if (ref != null) {
String[] boundaries = ref.split(":", 2);
String from = boundaries[0];
String to = boundaries[1];
startCellReference = new CellReference(from);
endCellReference = new CellReference(to);
}
}
use of org.apache.poi.ss.util.CellReference in project poi by apache.
the class XSSFTable method updateHeaders.
/**
* Synchronize table headers with cell values in the parent sheet.
* Headers <em>must</em> be in sync, otherwise Excel will display a
* "Found unreadable content" message on startup.
*
* If calling both {@link #updateReferences()} and
* {@link #updateHeaders()}, {@link #updateReferences()}
* should be called first.
*/
public void updateHeaders() {
XSSFSheet sheet = (XSSFSheet) getParent();
CellReference ref = getStartCellReference();
if (ref == null)
return;
int headerRow = ref.getRow();
int firstHeaderColumn = ref.getCol();
XSSFRow row = sheet.getRow(headerRow);
if (row != null && row.getCTRow().validate()) {
int cellnum = firstHeaderColumn;
for (CTTableColumn col : getCTTable().getTableColumns().getTableColumnArray()) {
XSSFCell cell = row.getCell(cellnum);
if (cell != null) {
col.setName(cell.getStringCellValue());
}
cellnum++;
}
ctColumns = null;
columnMap = null;
xmlColumnPr = null;
commonXPath = null;
}
}
use of org.apache.poi.ss.util.CellReference in project poi by apache.
the class TestXSSFComment method getSetRow.
@Test
public void getSetRow() {
CommentsTable sheetComments = new CommentsTable();
XSSFVMLDrawing vml = new XSSFVMLDrawing();
CTComment ctComment = sheetComments.newComment(CellAddress.A1);
CTShape vmlShape = vml.newCommentShape();
XSSFComment comment = new XSSFComment(sheetComments, ctComment, vmlShape);
comment.setRow(1);
assertEquals(1, comment.getRow());
assertEquals(1, new CellReference(ctComment.getRef()).getRow());
assertEquals(1, vmlShape.getClientDataArray(0).getRowArray(0).intValue());
comment.setRow(5);
assertEquals(5, comment.getRow());
assertEquals(5, new CellReference(ctComment.getRef()).getRow());
assertEquals(5, vmlShape.getClientDataArray(0).getRowArray(0).intValue());
}
Aggregations