Java Code Examples for org.apache.poi.ss.util.CellReference#formatAsString()

The following examples show how to use org.apache.poi.ss.util.CellReference#formatAsString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ForkedEvaluationSheet.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public ForkedEvaluationCell getOrCreateUpdatableCell(int rowIndex, int columnIndex) {
    RowColKey key = new RowColKey(rowIndex, columnIndex);

    ForkedEvaluationCell result = _sharedCellsByRowCol.get(key);
    if (result == null) {
        EvaluationCell mcell = _masterSheet.getCell(rowIndex, columnIndex);
        if (mcell == null) {
            CellReference cr = new CellReference(rowIndex, columnIndex);
            throw new UnsupportedOperationException("Underlying cell '"
                    + cr.formatAsString() + "' is missing in master sheet.");
        }
        result = new ForkedEvaluationCell(this, mcell);
        _sharedCellsByRowCol.put(key, result);
    }
    return result;
}
 
Example 2
Source File: AbstractHandler.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
protected void createName(HandlerState state, String bookmark, int row1, int col1, int row2, int col2 ) {
	CellReference crFirst = new CellReference( state.currentSheet.getSheetName(), row1, col1, true, true );
	CellReference crLast = new CellReference( row2, col2, true, true );
	String formula = crFirst.formatAsString() + ":" + crLast.formatAsString();

	Name name = state.currentSheet.getWorkbook().getName(bookmark);
	if( name == null ) {
		name = state.currentSheet.getWorkbook().createName();
		name.setNameName( bookmark ); 
		name.setRefersToFormula( formula );
	} else {
		String existingFormula = name.getRefersToFormula();
		try {
			name.setRefersToFormula(existingFormula + "," + formula);
		} catch( FormulaParseException ex ) {
			log.warn( 0, "Unable to add \"" + formula + "\" to name (\"" + bookmark + "\") with existing formula: " + existingFormula, ex );
		}
	}
}
 
Example 3
Source File: LazyRefEval.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public String toString() {
	CellReference cr = new CellReference(getRow(), getColumn());
	return getClass().getName() + "[" +
			_evaluator.getSheetNameRange() +
			'!' +
			cr.formatAsString() +
			"]";
}
 
Example 4
Source File: LazyAreaEval.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public String toString() {
	CellReference crA = new CellReference(getFirstRow(), getFirstColumn());
	CellReference crB = new CellReference(getLastRow(), getLastColumn());
	return getClass().getName() + "[" +
			_evaluator.getSheetNameRange() +
			'!' +
			crA.formatAsString() +
			':' +
			crB.formatAsString() +
			"]";
}
 
Example 5
Source File: WorkbookEvaluator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds the current cell reference to the exception for easier debugging.
 * Would be nice to get the formula text as well, but that seems to require
 * too much digging around and casting to get the FormulaRenderingWorkbook.
 */
private NotImplementedException addExceptionInfo(NotImplementedException inner, int sheetIndex, int rowIndex, int columnIndex) {

    try {
        String sheetName = _workbook.getSheetName(sheetIndex);
        CellReference cr = new CellReference(sheetName, rowIndex, columnIndex, false, false);
        String msg =  "Error evaluating cell " + cr.formatAsString();
        return new NotImplementedException(msg, inner);
    } catch (Exception e) {
        // avoid bombing out during exception handling
        LOG.log(POILogger.ERROR, "Can't add exception info", e);
        return inner; // preserve original exception
    }
}
 
Example 6
Source File: AreaPtgBase.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected final String formatReferenceAsString() {
    CellReference topLeft = new CellReference(getFirstRow(),getFirstColumn(),!isFirstRowRelative(),!isFirstColRelative());
    CellReference botRight = new CellReference(getLastRow(),getLastColumn(),!isLastRowRelative(),!isLastColRelative());

    if(AreaReference.isWholeColumnReference(SpreadsheetVersion.EXCEL97, topLeft, botRight)) {
        return (new AreaReference(topLeft, botRight, SpreadsheetVersion.EXCEL97)).formatAsString();
    }
    return topLeft.formatAsString() + ":" + botRight.formatAsString();
}
 
Example 7
Source File: FormulaRecordAggregate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public CellRangeAddress getArrayFormulaRange() {
	if (_sharedFormulaRecord != null) {
		throw new IllegalStateException("not an array formula cell.");
	}
	CellReference expRef = _formulaRecord.getFormula().getExpReference();
	if (expRef == null) {
		throw new IllegalStateException("not an array formula cell.");
	}
	ArrayRecord arec = _sharedValueManager.getArrayRecord(expRef.getRow(), expRef.getCol());
	if (arec == null) {
		throw new IllegalStateException("ArrayRecord was not found for the locator " + expRef.formatAsString());
	}
	CellRangeAddress8Bit a = arec.getRange();
	return new CellRangeAddress(a.getFirstRow(), a.getLastRow(), a.getFirstColumn(),a.getLastColumn());
}
 
Example 8
Source File: SharedValueManager.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public SharedFormulaGroup(SharedFormulaRecord sfr, CellReference firstCell) {
	if (!sfr.isInRange(firstCell.getRow(), firstCell.getCol())) {
		throw new IllegalArgumentException("First formula cell " + firstCell.formatAsString()
				+ " is not shared formula range " + sfr.getRange() + ".");
	}
	_sfr = sfr;
	_firstCell = firstCell;
	int width = sfr.getLastColumn() - sfr.getFirstColumn() + 1;
	int height = sfr.getLastRow() - sfr.getFirstRow() + 1;
	_frAggs = new FormulaRecordAggregate[width * height];
	_numberOfFormulas = 0;
}
 
Example 9
Source File: RefPtgBase.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected final String formatReferenceAsString() {
	// Only make cell references as needed. Memory is an issue
	CellReference cr = new CellReference(getRow(), getColumn(), !isRowRelative(), !isColRelative());
	return cr.formatAsString();
}
 
Example 10
Source File: HyperlinksTest.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
protected static String buildCellReference( int zeroBasedRow, int zeroBasedCol ) {
	CellReference cr = new CellReference(zeroBasedRow, zeroBasedCol);
	return cr.formatAsString();
}
 
Example 11
Source File: HSSFCell.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Called when this cell is modified.
 * <p>
 * The purpose of this method is to validate the cell state prior to modification.
 * </p>
 *
 * @see #setCellType(int)
 * @see #setCellFormula(String)
 * @see HSSFRow#removeCell(org.apache.poi.ss.usermodel.Cell)
 * @see org.apache.poi.hssf.usermodel.HSSFSheet#removeRow(org.apache.poi.ss.usermodel.Row)
 * @see org.apache.poi.hssf.usermodel.HSSFSheet#shiftRows(int, int, int)
 * @see org.apache.poi.hssf.usermodel.HSSFSheet#addMergedRegion(org.apache.poi.ss.util.CellRangeAddress)
 * @throws IllegalStateException if modification is not allowed
 */
void notifyArrayFormulaChanging(){
    CellReference ref = new CellReference(this);
    String msg = "Cell "+ref.formatAsString()+" is part of a multi-cell array formula. " +
            "You cannot change part of an array.";
    notifyArrayFormulaChanging(msg);
}