List of usage examples for org.apache.poi.ss.usermodel Cell getSheet
Sheet getSheet();
From source file:org.netxilia.impexp.impl.ExcelExportService.java
License:Open Source License
private void copyCellValue(CellData nxCell, Cell poiCell) { if (nxCell.getValue() == null) { return;/*from ww w .j a va2 s .c om*/ } if (nxCell.getFormula() != null) { // remove leading = poiCell.setCellFormula(nxCell.getFormula().getFormula().substring(1)); return; } switch (nxCell.getValue().getValueType()) { case BOOLEAN: poiCell.setCellValue(nxCell.getValue().getBooleanValue()); break; case NUMBER: poiCell.setCellValue(nxCell.getValue().getNumberValue()); break; case DATE: poiCell.setCellValue(nxCell.getValue().getDateValue().toDateTime(DateValue.ORIGIN).toDate()); break; case ERROR: // TODO translate errors // poiCell.setCellErrorValue(((ErrorValue)nxCell.getValue()).getErrorType()); break; case STRING: poiCell.setCellValue(nxCell.getValue().getStringValue()); break; } poiCell.setCellStyle(PoiUtils.netxiliaStyle2Poi(nxCell.getStyles(), poiCell.getSheet().getWorkbook())); }
From source file:org.netxilia.impexp.impl.ExcelImportService.java
License:Open Source License
private ICellCommand copyCell(Cell poiCell, CellReference cellReference, HSSFPalette palette, NetxiliaStyleResolver styleResolver) throws FormulaParsingException { CellStyle poiStyle = poiCell.getCellStyle(); Styles styles = PoiUtils.poiStyle2Netxilia(poiStyle, poiCell.getSheet().getWorkbook().getFontAt(poiStyle.getFontIndex()), palette, styleResolver); IGenericValue value = null;/*w w w. j a v a 2 s. c om*/ Formula formula = null; // log.info("CELL TYPE:" + cellReference + " type:" + poiCell.getCellType() + " " // + (poiCell.getCellType() == Cell.CELL_TYPE_FORMULA ? poiCell.getCellFormula() : "no")); switch (poiCell.getCellType()) { // TODO translate errors case Cell.CELL_TYPE_STRING: value = new StringValue(poiCell.getStringCellValue()); break; case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(poiCell)) { DateTime dt = new DateTime(poiCell.getDateCellValue()); // TODO decide whether is date or time if (dt.isBefore(EXCEL_START)) { value = new DateValue(dt.toLocalTime()); } else if (dt.getMillisOfDay() == 0) { value = new DateValue(dt.toLocalDate()); } else { value = new DateValue(dt.toLocalDateTime()); } } else { value = new NumberValue(poiCell.getNumericCellValue()); } break; case Cell.CELL_TYPE_BOOLEAN: value = new BooleanValue(poiCell.getBooleanCellValue()); break; case Cell.CELL_TYPE_FORMULA: if (poiCell.getCellFormula() != null) { formula = formulaParser.parseFormula(new Formula("=" + poiCell.getCellFormula())); } break; } if ((styles == null || styles.getItems().isEmpty()) && formula == null && (value == null || value.equals(GenericValueUtils.EMTPY_STRING))) { return null; } return CellCommands.cell(new AreaReference(cellReference), value, formula, styles); }
From source file:org.openelis.bean.WorksheetExcelHelperBean.java
License:Open Source License
private Object getCellValue(Cell cell) { Object value;/*from w w w . java 2 s . c om*/ FormulaEvaluator eval; value = null; if (cell != null) { switch (cell.getCellType()) { case Cell.CELL_TYPE_FORMULA: eval = cell.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator(); switch (eval.evaluateFormulaCell(cell)) { case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { value = new Datetime(Datetime.YEAR, Datetime.MINUTE, cell.getDateCellValue()); } else { cell.setCellType(Cell.CELL_TYPE_STRING); value = cell.getStringCellValue(); if (((String) value).trim().length() == 0) value = null; } break; case Cell.CELL_TYPE_STRING: value = cell.getStringCellValue(); if (((String) value).trim().length() == 0) value = null; break; } break; case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { value = new Datetime(Datetime.YEAR, Datetime.MINUTE, cell.getDateCellValue()); } else { cell.setCellType(Cell.CELL_TYPE_STRING); value = cell.getStringCellValue(); if (((String) value).trim().length() == 0) value = null; } break; case Cell.CELL_TYPE_STRING: value = cell.getStringCellValue(); if (((String) value).trim().length() == 0) value = null; break; } } return value; }
From source file:org.tiefaces.components.websheet.configuration.ConfigurationHandler.java
License:MIT License
/** * change the comment.//from w w w.ja 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.j av 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.service.ValidationHandler.java
License:MIT License
/** * Validate by tie web sheet validation bean. * * @param poiCell the poi cell//from ww w . j a va 2s . c om * @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 w w . j a v a 2 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 ww w . j a v a 2s .co 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; }
From source file:org.tiefaces.components.websheet.utility.CellControlsUtility.java
License:MIT License
/** * Setup control attributes.//from w w w .jav a2 s.c o m * * @param originRowIndex * the origin row index * @param fcell * the fcell * @param poiCell * the poi cell * @param sheetConfig * the sheet config * @param cellAttributesMap * the cell attributes map */ public static void setupControlAttributes(final int originRowIndex, final FacesCell fcell, final Cell poiCell, final SheetConfiguration sheetConfig, final CellAttributesMap cellAttributesMap) { int rowIndex = originRowIndex; if (rowIndex < 0) { rowIndex = poiCell.getRowIndex(); } String skey = poiCell.getSheet().getSheetName() + "!" + CellUtility.getCellIndexNumberKey(poiCell.getColumnIndex(), rowIndex); Map<String, String> commentMap = cellAttributesMap.getTemplateCommentMap().get("$$"); if (commentMap != null) { String comment = commentMap.get(skey); if (comment != null) { CommandUtility.createCellComment(poiCell, comment, sheetConfig.getFinalCommentMap()); } } String widgetType = cellAttributesMap.getCellInputType().get(skey); if (widgetType != null) { fcell.setControl(widgetType.toLowerCase()); fcell.setInputAttrs(cellAttributesMap.getCellInputAttributes().get(skey)); fcell.setSelectItemAttrs(cellAttributesMap.getCellSelectItemsAttributes().get(skey)); fcell.setDatePattern(cellAttributesMap.getCellDatePattern().get(skey)); } }
From source file:org.tiefaces.components.websheet.utility.CellControlsUtility.java
License:MIT License
/** * Find cell validate attributes.//from w w w . j ava 2s . c om * * @param validateMaps * validateMaps. * @param originRowIndex * original Row Index from facesRow. * @param cell * cell. * @return list. */ public static List<CellFormAttributes> findCellValidateAttributes( final Map<String, List<CellFormAttributes>> validateMaps, final int originRowIndex, final Cell cell) { String key = cell.getSheet().getSheetName() + "!" + CellUtility.getCellIndexNumberKey(cell.getColumnIndex(), originRowIndex); return validateMaps.get(key); }