Usages of

org.apache.poi.xssf.streaming.SXSSFCell.getFormulaValue()
private void setCellData(){ SXSSFCell sxssfCell = _xssfCellExportContext.getExcelCell(); DataType dataType = _xssfCellExportContext.getDataType(); String data = _xssfCellExportContext.getData(); Map<String,Object> contentMap = _xssfCellExportContext.contentMap(); String tableColumn =(String) _xssfCellExportContext.getVariable("tableColumn"); if(tableColumn != null){ dataType = DataType.string; data = tableColumn; } try{ switch(dataType){ case formula: sxssfCell.setCellType(Cell.CELL_TYPE_FORMULA); Object fv = _xssfCellExportContext.getFormulaValue(); if(fv != null){ if(fv instanceof Number){ sxssfCell.setCellValue(((Number)fv).doubleValue()); }else{ String fvString = fv.toString(); Double fvDouble = Doubles.tryParse(fvString); if(fvDouble != null){ // if value is numeric, we cached sxssfCell.setCellValue(fvDouble); }else{ // else we miss it.It helps we import. sxssfCell.setCellValue(""); } } } sxssfCell.setCellFormula(SpreadsheetExportHelper.filterFormulaIllegalCharacter(data.substring(1))); Integer afrow = (Integer)contentMap.get("afrow"); Integer aerow = (Integer)contentMap.get("aerow"); Integer afcol = (Integer)contentMap.get("afcol"); Integer aecol = (Integer)contentMap.get("aecol"); if(afrow != null && afcol != null ){ Map<String,String> attributes = new HashMap<>(); attributes.put("ca", "1"); if(aerow != null && aecol != null){ int rowIndex= _xssfCellExportContext.sheetCell().getX(); int columnIndex = _xssfCellExportContext.sheetCell().getY(); attributes.put("aca", "1"); attributes.put("ref", CellReference.convertNumToColString(columnIndex-1)+rowIndex+":"+CellReference.convertNumToColString(columnIndex+aecol-1)+(rowIndex+aerow)); attributes.put("t", "array"); }else{ sxssfCell.setCellFormula(""); } sxssfCell.getFormulaValue().setAttributes(attributes); } break; case bool: sxssfCell.setCellType(Cell.CELL_TYPE_BOOLEAN); sxssfCell.setCellValue(Boolean.valueOf(data.toLowerCase())); break; case string: sxssfCell.setCellType(Cell.CELL_TYPE_STRING); sxssfCell.setCellValue(data); break; case numeric: sxssfCell.setCellType(Cell.CELL_TYPE_NUMERIC); sxssfCell.setCellValue(Double.parseDouble(data)); break; case date: Date javaDate = DateTimeUtil.parseAsYYYYMMdd(data); sxssfCell.setCellValue(javaDate); break; case time: double timeValue = convertTimeAsDouble(data); sxssfCell.setCellValue(timeValue); break; case datetime: Date javaDatetime = DateTimeUtil.parseAsYYYYMMddHHmmss(data); sxssfCell.setCellValue(javaDatetime); break; case error: sxssfCell.setCellType(Cell.CELL_TYPE_ERROR); sxssfCell.setCellValue(data); break; case blank: sxssfCell.setCellType(Cell.CELL_TYPE_BLANK); break; } }catch(Exception ex){ sxssfCell.setCellType(Cell.CELL_TYPE_STRING); sxssfCell.setCellValue(_xssfCellExportContext.sheetCell().getRawData()); } }
Usage snippet has been bookmarked! Review your bookmarks
Thank you! Review your likes