List of usage examples for org.apache.poi.ss.usermodel Cell getRowIndex
int getRowIndex();
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 . j a v a2 s. c o m }
From source file:org.talend.dataprep.schema.xls.XlsUtils.java
License:Open Source License
/** * * @param cell/* w ww . j a v a2 s . 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 ww w . jav a2s . com * * @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.ConfigRangeAttrs.java
License:MIT License
/** * Gets the first row index./* w w w.j av a 2s. c om*/ * * @return the first row index */ public final int getFirstRowIndex() { Cell cell = this.getFirstRowRef(); if (cell != null) { return cell.getRowIndex(); } return -1; }
From source file:org.tiefaces.components.websheet.configuration.ConfigRangeAttrs.java
License:MIT License
/** * Gets the last row index./*from w w w . java 2s .co m*/ * * @return the last row index */ public final int getLastRowIndex() { Cell cell = this.getLastRowPlusRef(); if (cell != null) { return cell.getRowIndex() - 1; } return -1; }
From source file:org.tiefaces.components.websheet.configuration.ConfigurationHandler.java
License:MIT License
/** * change the comment./*w w w .ja v a 2s.com*/ * * @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.serializable.SerialCellAddress.java
License:MIT License
/** * Create a new CellAddress object./*from w ww . j ava 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/*w w w .j ava2 s . c o 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/* w ww. ja v a 2s. co m*/ * @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 .jav a 2 s . c om * * @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; }