Example usage for org.apache.poi.ss.usermodel Cell getColumnIndex

List of usage examples for org.apache.poi.ss.usermodel Cell getColumnIndex

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Cell getColumnIndex.

Prototype

int getColumnIndex();

Source Link

Document

Returns column index of this cell

Usage

From source file:org.squashtest.tm.service.internal.batchimport.excel.TypeBasedCellValueCoercer.java

License:Open Source License

private CannotCoerceException cannotCoerceFunky(Cell cell) {
    return new CannotCoerceException("Cannot coerce cell [R," + cell.getRowIndex() + " C"
            + cell.getColumnIndex() + "] of unhandled type", Messages.ERROR_FUNKY_CELL_TYPE);

}

From source file:org.squashtest.tm.service.internal.batchimport.excel.TypeBasedCellValueCoercer.java

License:Open Source License

private CannotCoerceException cannotCoerce(String type, Cell cell, String errorI18nKey) {
    return new CannotCoerceException(
            "Cannot coerce cell [R," + cell.getRowIndex() + " C" + cell.getColumnIndex() + "] of type " + type,
            errorI18nKey);/*from   w w  w  . ja  v  a 2 s  .c o  m*/
}

From source file:org.talend.dataprep.schema.xls.XlsUtils.java

License:Open Source License

/**
 *
 * @param cell//from   ww w .  java 2s.c o m
 * @param formulaEvaluator
 * @return return the cell value as String (if needed evaluate the existing formula)
 */
public static String getCellValueAsString(Cell cell, FormulaEvaluator formulaEvaluator) {
    if (cell == null) {
        return StringUtils.EMPTY;
    }
    switch (cell.getCellType()) {
    case Cell.CELL_TYPE_BLANK:
        return "";
    case Cell.CELL_TYPE_BOOLEAN:
        return cell.getBooleanCellValue() ? Boolean.TRUE.toString() : Boolean.FALSE.toString();
    case Cell.CELL_TYPE_ERROR:
        return "Cell Error type";
    case Cell.CELL_TYPE_FORMULA:
        try {
            return getCellValueAsString(cell, formulaEvaluator.evaluate(cell));
        } catch (Exception e) {
            // log error message and the formula
            LOGGER.warn("Unable to evaluate cell (line: {}, col: {}) with formula '{}': {}", cell.getRowIndex(),
                    cell.getColumnIndex(), cell.getCellFormula(), e.getMessage(), e);
            return StringUtils.EMPTY;
        }
    case Cell.CELL_TYPE_NUMERIC:
        return getNumericValue(cell, null, false);
    case Cell.CELL_TYPE_STRING:
        return StringUtils.trim(cell.getStringCellValue());
    default:
        return "Unknown Cell Type: " + cell.getCellType();
    }
}

From source file:org.tiefaces.components.websheet.configuration.ConfigRange.java

License:MIT License

/**
 * Builds the single cell./*from   w ww  .  j a  v a  2s.  c  o m*/
 *
 * @param cell
 *            the cell
 * @param context
 *            the context
 * @param configBuildRef
 *            the config build ref
 * @param shiftFormulaRef
 *            the shift formula ref
 */
private void buildSingleCell(final Cell cell, final Map<String, Object> context,
        final ConfigBuildRef configBuildRef, final ShiftFormulaRef shiftFormulaRef) {
    try {
        CommandUtility.evaluate(context, cell, configBuildRef.getEngine());
        if (cell.getCellTypeEnum() == CellType.FORMULA) {
            // rebuild formula if necessary for dynamic row
            String originFormula = cell.getCellFormula();
            shiftFormulaRef.setFormulaChanged(0);
            ConfigurationUtility.buildCellFormulaForShiftedRows(configBuildRef.getSheet(),
                    configBuildRef.getWbWrapper(), shiftFormulaRef, cell, cell.getCellFormula());
            if (shiftFormulaRef.getFormulaChanged() > 0) {
                configBuildRef.getCachedCells().put(cell, originFormula);
            }
        }

    } catch (Exception ex) {
        LOG.log(Level.SEVERE, "build cell ( row = " + cell.getRowIndex() + " column = " + cell.getColumnIndex()
                + " error = " + ex.getLocalizedMessage(), ex);
    }
}

From source file:org.tiefaces.components.websheet.configuration.ConfigurationHandler.java

License:MIT License

/**
 * change the comment./*from  w w  w .j  a  v  a 2 s . c  o m*/
 *
 * @param cell
 *            the cell
 * @param newComment
 *            updated comment.
 * @param sheetCommentMap
 *            the sheet comment map
 * @param normalComment
 *            the normal comment
 */
private void moveCommentToMap(final Cell cell, final String newComment,
        final Map<String, Map<String, String>> sheetCommentMap, final boolean normalComment) {

    String cellKey = cell.getSheet().getSheetName() + "!$" + cell.getColumnIndex() + "$" + cell.getRowIndex();

    ParserUtility.parseCommentToMap(cellKey, newComment, sheetCommentMap, normalComment);

}

From source file:org.tiefaces.components.websheet.dataobjects.CellMap.java

License:MIT License

@Override
public final Object put(final Object key, final Object value) {
    try {/*from   w  w w  .  ja  v  a  2  s .  c o m*/
        CellMapKey mkey = new CellMapKey((String) key);
        if (!mkey.isParseSuccess()) {
            return null;
        }
        Cell poiCell = parent.getCellHelper().getPoiCellWithRowColFromCurrentPage(mkey.getRowIndex(),
                mkey.getColIndex());
        if (poiCell == null) {
            return null;
        }
        String oldValue = CellUtility.getCellValueWithoutFormat(poiCell);
        FacesCell facesCell = parent.getCellHelper().getFacesCellWithRowColFromCurrentPage(mkey.getRowIndex(),
                mkey.getColIndex());
        String newValue = assembleNewValue(value, facesCell);
        if (newValue != null && !newValue.equals(oldValue)) {
            CellUtility.setCellValue(poiCell, newValue);
            if (facesCell.isHasSaveAttr()) {
                parent.getCellHelper().saveDataInContext(poiCell, newValue);
            }
            // patch to avoid not updated downloaded file
            CellUtility.copyCell(poiCell.getSheet(), poiCell.getRow(), poiCell.getRow(),
                    poiCell.getColumnIndex(), false);
            parent.getCellHelper().reCalc();
        }

        return value;
    } catch (Exception ex) {
        LOG.log(Level.SEVERE, "Save cell data error : " + ex.getLocalizedMessage(), ex);
    }
    return null;
}

From source file:org.tiefaces.components.websheet.serializable.SerialCellAddress.java

License:MIT License

/**
 * Create a new CellAddress object.//from w  ww . j  a v  a  2 s. c o m
 *
 * @param cell
 *            the Cell to get the location of
 */
public SerialCellAddress(final Cell cell) {
    if (cell != null) {
        this.row = cell.getRowIndex();
        this.col = cell.getColumnIndex();
    }
}

From source file:org.tiefaces.components.websheet.service.ValidationHandler.java

License:MIT License

/**
 * Validate by tie web sheet validation bean.
 *
 * @param poiCell the poi cell//from   w w  w .  j  a v a 2s. co m
 * @param topRow the top row
 * @param leftCol the left col
 * @param cell the cell
 * @param value the value
 * @param updateGui the update gui
 * @return true, if successful
 */
private boolean validateByTieWebSheetValidationBean(final Cell poiCell, final int topRow, final int leftCol,
        final FacesCell cell, final String value, boolean updateGui) {
    if (parent.getTieWebSheetValidationBean() != null) {
        String errormsg = null;
        String fullName = ConfigurationUtility.getFullNameFromRow(poiCell.getRow());
        String saveAttr = SaveAttrsUtility.prepareContextAndAttrsForCell(poiCell, fullName,
                parent.getCellHelper());
        if (saveAttr != null) {
            int row = poiCell.getRowIndex();
            int col = poiCell.getColumnIndex();
            errormsg = parent.getTieWebSheetValidationBean().validate(
                    parent.getSerialDataContext().getDataContext(), saveAttr,
                    ConfigurationUtility.getFullNameFromRow(poiCell.getRow()),
                    poiCell.getSheet().getSheetName(), row, col, value);
            if ((errormsg != null) && (!errormsg.isEmpty())) {
                cell.setErrormsg(errormsg);
                refreshAfterStatusChanged(false, true, row - topRow, col - leftCol, cell, updateGui);
                return false;
            }
        }
    }
    return true;
}

From source file:org.tiefaces.components.websheet.service.ValidationHandler.java

License:MIT License

/**
 * Check error message from object in context.
 *
 * @param formRow the form row/*from w w w .  j ava2  s . com*/
 * @param formCol the form col
 * @param cell the cell
 * @param poiCell the poi cell
 * @param value the value
 * @param sheetConfig the sheet config
 * @param updateGui the update gui
 * @return true, if successful
 */
private boolean checkErrorMessageFromObjectInContext(final int formRow, final int formCol, final FacesCell cell,
        final Cell poiCell, final String value, final SheetConfiguration sheetConfig, boolean updateGui) {

    @SuppressWarnings("unchecked")
    HashMap<String, TieCell> tieCells = (HashMap<String, TieCell>) parent.getSerialDataContext()
            .getDataContext().get("tiecells");

    if (tieCells != null) {

        TieCell tieCell = tieCells.get(CellUtility.getSkeyFromPoiCell(poiCell));

        if (tieCell != null && tieCell.getContextObject() != null) {

            String errorMethod = tieCell.getMethodStr() + parent.getConfigAdvancedContext().getErrorSuffix();

            String errorMessage = CellControlsUtility.getObjectPropertyValue(tieCell.getContextObject(),
                    errorMethod, true);

            if (errorMessage != null && !errorMessage.isEmpty()) {
                cell.setErrormsg(errorMessage);
                LOG.log(Level.INFO, "Validation failed for sheet {0} row {1} column {2} : {3}",
                        new Object[] { poiCell.getSheet().getSheetName(), poiCell.getRowIndex(),
                                poiCell.getColumnIndex(), errorMessage });
                refreshAfterStatusChanged(false, true, formRow, formCol, cell, updateGui);
                return false;
            }

        }
    }

    return true;

}

From source file:org.tiefaces.components.websheet.service.ValidationHandler.java

License:MIT License

/**
 * Validate all rules for single cell./*from   w  w  w . j  a  v  a2s  .c o m*/
 *
 * @param formRow            the form row
 * @param formCol            the form col
 * @param cell            the cell
 * @param poiCell            the poi cell
 * @param value            the value
 * @param sheetConfig            the sheet config
 * @param cellAttributes            the cell attributes
 * @param updateGui the update gui
 * @return true, if successful
 */
private boolean validateAllRulesForSingleCell(final int formRow, final int formCol, final FacesCell cell,
        final Cell poiCell, final String value, final SheetConfiguration sheetConfig,
        final List<CellFormAttributes> cellAttributes, boolean updateGui) {
    Sheet sheet1 = parent.getWb().getSheet(sheetConfig.getSheetName());
    for (CellFormAttributes attr : cellAttributes) {
        boolean pass = doValidation(value, attr, poiCell.getRowIndex(), poiCell.getColumnIndex(), sheet1);
        if (!pass) {
            String errmsg = attr.getMessage();
            if (errmsg == null) {
                errmsg = TieConstants.DEFALT_MSG_INVALID_INPUT;
            }
            cell.setErrormsg(errmsg);
            LOG.log(Level.INFO, "Validation failed for sheet {0} row {1} column {2} : {3}",
                    new Object[] { poiCell.getSheet().getSheetName(), poiCell.getRowIndex(),
                            poiCell.getColumnIndex(), errmsg });
            refreshAfterStatusChanged(false, true, formRow, formCol, cell, updateGui);
            return false;
        }

    }
    return true;
}