List of usage examples for org.apache.poi.ss.usermodel Cell getStringCellValue
String getStringCellValue();
For numeric cells we throw an exception.
From source file:com.github.cutstock.excel.model.SheetBuilder.java
License:Apache License
public SheetBuilder createColumns(ICellInfo columns) { IExcelRectangle rect = columns.getRect(); int rowLine = rect.getStartRow(); Row row = createRow(rowLine);/* w ww . ja va2 s. c om*/ // String colName = columns.getText(); // String[] colNames = colName.split(","); Object[] colNames = columns.getColumns(); for (int i = rect.getStartCol(), j = rect.getEndCol(), index = 0; i <= j; i++, index++) { Cell colCell = row.createCell(i); // cut num should cast to number 5,13 if (colNames[index] instanceof BigDecimal || colNames[index] instanceof Integer) { colCell.setCellValue(Double.parseDouble(colNames[index].toString())); colCell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); } else { colCell.setCellValue(colNames[index].toString()); } CellStyle style = styles.get(columns.getCellType().typeValue()); colCell.setCellStyle(style); } Row preRow = createRow(rowLine - 1); if (preRow != null) { Cell nameCel = preRow.getCell(rect.getStartCol()); if (nameCel != null) { if (nameCel.getStringCellValue().equals(row.getCell(rect.getStartCol()).getStringCellValue())) { mergeRegion(ExcelModelFactory.createCellRect(rect.getStartCol(), rect.getStartCol(), rowLine - 1, rowLine)); } } } return this; }
From source file:com.github.drbookings.excel.FileFormatBookingXLS.java
License:Open Source License
public static int getBookingNumber(final Cell c) { if (c != null) { if (c.getCellType() == Cell.CELL_TYPE_NUMERIC) { return (int) c.getNumericCellValue(); } else {/* www . j a v a 2s . c o m*/ final String cellContent = c.getStringCellValue(); try { return Integer.parseInt(cellContent); } catch (final Exception e) { if (logger.isWarnEnabled()) { logger.warn("Failed to parse booking number from " + cellContent); } } } } return NA_INT; }
From source file:com.github.drbookings.excel.FileFormatBookingXLS.java
License:Open Source License
public static int getColumnIndexForIdentifier(final Row row, final String identifierBookingNumber) throws ExceptionFileFormat { final Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { final Cell nextCell = cellIterator.next(); final String cellContent = nextCell.getStringCellValue(); if (cellContent.equals(identifierBookingNumber)) { return nextCell.getColumnIndex(); }/*from w ww . j a v a2s . c o m*/ } throw new ExceptionFileFormat("Failed to parse " + identifierBookingNumber); }
From source file:com.github.drbookings.excel.FileFormatBookingXLS.java
License:Open Source License
public static LocalDate getDate(final Cell cell) { if (cell != null) { final String result = cell.getStringCellValue(); if (result != null && !StringUtils.isEmpty(result)) { return LocalDate.parse(result); }/*from w ww . j av a 2 s. com*/ } return null; }
From source file:com.github.drbookings.excel.FileFormatBookingXLS.java
License:Open Source License
public static String getString(final Cell cell) { if (cell != null) { final String result = cell.getStringCellValue(); if (!StringUtils.isEmpty(result)) { return result; }//w ww.j av a2s.c o m } return null; }
From source file:com.github.jferard.spreadsheetwrapper.xls.poi.XlsPoiWriter.java
License:Open Source License
/** {@inheritDoc} */ @Override//from w w w .j a va 2s . co m public/*@Nullable*/Object getCellContent(final int rowIndex, final int colIndex) { final Cell cell = this.getPOICell(rowIndex, colIndex); if (cell == null) return null; Object result; switch (cell.getCellType()) { case Cell.CELL_TYPE_BLANK: result = null; break; case Cell.CELL_TYPE_BOOLEAN: result = Boolean.valueOf(cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_ERROR: result = "#Err"; break; case Cell.CELL_TYPE_FORMULA: result = cell.getCellFormula(); break; case Cell.CELL_TYPE_NUMERIC: if (this.isDate(cell)) { result = cell.getDateCellValue(); } else { final double value = cell.getNumericCellValue(); if (value == Math.rint(value)) result = Integer.valueOf((int) value); else result = value; } break; case Cell.CELL_TYPE_STRING: result = cell.getStringCellValue(); break; default: throw new IllegalArgumentException(String.format("Unknown type of cell %d", cell.getCellType())); } return result; }
From source file:com.github.jferard.spreadsheetwrapper.xls.poi.XlsPoiWriter.java
License:Open Source License
/** {@inheritDoc} */ @Override/*from w ww.j a va 2s. c om*/ public/*@Nullable*/String getText(final int r, final int c) { final Cell cell = this.getPOICell(r, c); if (XlsPoiWriter.nullCellOrInvalidType(cell, Cell.CELL_TYPE_STRING)) return null; return cell.getStringCellValue(); }
From source file:com.github.ko2ic.plugin.eclipse.taggen.core.domain.model.spreadsheet.SheetImpl.java
License:Open Source License
/** * Get the value of the cell as a string . * @param cell a cell in spreadsheet//from w w w .jav a 2s . co m * @return */ private String getStringCellValue(Cell cell) { int type = cell.getCellType(); String result = null; if (type == Cell.CELL_TYPE_STRING) { result = cell.getStringCellValue(); } else if (type == Cell.CELL_TYPE_NUMERIC) { result = String.valueOf((int) cell.getNumericCellValue()); } return result; }
From source file:com.github.svrtm.xlreport.ACell.java
License:Apache License
void setAutoSizeColumn(final Cell poiCell) { boolean enableAutoSize = false; final int cellType = poiCell.getCellType(); switch (cellType) { case Cell.CELL_TYPE_STRING: { final String value = poiCell.getStringCellValue(); if (value != null && value.length() >= AUTOSIZE_MIN_LENGTH) { final String tr = value.trim(); for (int i = 0; i < tr.length(); i++) if (Character.isWhitespace(tr.charAt(i)) == false) { enableAutoSize = true; break; }/*from w ww .ja v a 2 s . c o m*/ } break; } case Cell.CELL_TYPE_BLANK: break; default: enableAutoSize = true; } if (enableAutoSize) builder.sheet.autoSizeColumn(poiCell.getColumnIndex()); }
From source file:com.github.xiilei.ecdiff.Processor.java
License:Apache License
public String getStringCellValue(Cell cell) { String value = ""; switch (cell.getCellType()) { case Cell.CELL_TYPE_BLANK: value = ""; break;// w ww. j av a2 s . c o m case Cell.CELL_TYPE_BOOLEAN: value = String.valueOf(cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_STRING: value = cell.getStringCellValue(); cell.getRichStringCellValue(); break; case Cell.CELL_TYPE_NUMERIC: value = String.valueOf(cell.getNumericCellValue()); break; case Cell.CELL_TYPE_ERROR: value = ""; break; } return value.trim().replace(" ", ""); }