Java Code Examples for org.apache.poi.hssf.usermodel.HSSFCell#getNumericCellValue()
The following examples show how to use
org.apache.poi.hssf.usermodel.HSSFCell#getNumericCellValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImportService.java From lams with GNU General Public License v2.0 | 6 votes |
private boolean parseBooleanCell(HSSFCell cell) { if (cell != null) { String value; try { cell.setCellType(CellType.STRING); if (cell.getStringCellValue() != null) { if (cell.getStringCellValue().trim().length() != 0) { emptyRow = false; } } else { return false; } value = cell.getStringCellValue().trim(); } catch (Exception e) { cell.setCellType(CellType.NUMERIC); double d = cell.getNumericCellValue(); emptyRow = false; value = new Long(new Double(d).longValue()).toString(); } if (StringUtils.equals(value, "1") || StringUtils.equalsIgnoreCase(value, "true")) { return true; } } return false; }
Example 2
Source File: POIUtils.java From ermasterr with Apache License 2.0 | 6 votes |
public static int getIntCellValue(final HSSFSheet sheet, final int r, final int c) { final HSSFRow row = sheet.getRow(r); if (row == null) { return 0; } final HSSFCell cell = row.getCell(c); try { if (cell.getCellType() != Cell.CELL_TYPE_NUMERIC) { return 0; } } catch (final RuntimeException e) { System.err.println("Exception at sheet name:" + sheet.getSheetName() + ", row:" + (r + 1) + ", col:" + (c + 1)); throw e; } return (int) cell.getNumericCellValue(); }
Example 3
Source File: XlsSessionReader.java From conference-app with MIT License | 6 votes |
private String getCellValue(HSSFCell cell) { String result = null; if (cell != null) { switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_FORMULA: result = cell.getCellFormula().toString(); break; case HSSFCell.CELL_TYPE_NUMERIC: result = "" + cell.getNumericCellValue(); break; case HSSFCell.CELL_TYPE_STRING: result = cell.getStringCellValue(); break; default: } } return result; }
Example 4
Source File: PoiUtil.java From dk-fitting with Apache License 2.0 | 5 votes |
/** * 获取单元格中的内容 ,该犯法用于解析各种形式的数据 */ private Object getCellString(HSSFCell cell) { Object result = null; if (cell != null) { int cellType = cell.getCellType(); switch (cellType) { case HSSFCell.CELL_TYPE_STRING: result = cell.getRichStringCellValue().getString(); break; case HSSFCell.CELL_TYPE_NUMERIC: result = cell.getNumericCellValue(); break; case HSSFCell.CELL_TYPE_FORMULA: result = cell.getNumericCellValue(); break; case HSSFCell.CELL_TYPE_ERROR: result = null; break; case HSSFCell.CELL_TYPE_BOOLEAN: result = cell.getBooleanCellValue(); break; case HSSFCell.CELL_TYPE_BLANK: result = null; break; default: break; } } return result; }
Example 5
Source File: ImportService.java From lams with GNU General Public License v2.0 | 5 votes |
private String parseStringCell(HSSFCell cell) { if (cell != null) { try { cell.setCellType(CellType.STRING); if (cell.getStringCellValue() != null) { if (cell.getStringCellValue().trim().length() != 0) { emptyRow = false; } } else { return null; } // log.debug("string cell value: '"+cell.getStringCellValue().trim()+"'"); return cell.getStringCellValue().trim(); } catch (Exception e) { cell.setCellType(CellType.NUMERIC); double d = cell.getNumericCellValue(); emptyRow = false; // log.debug("numeric cell value: '"+d+"'"); return (new Long(new Double(d).longValue()).toString()); } } return null; }
Example 6
Source File: XLSFileNormalizer.java From Knowage-Server with GNU Affero General Public License v3.0 | 5 votes |
private String parseCell(HSSFCell cell) { String valueField = null; if(cell == null) return ""; switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_FORMULA: valueField = cell.getCellFormula().toString(); break; case HSSFCell.CELL_TYPE_NUMERIC: Double numericValue = cell.getNumericCellValue(); //testing if the double is an integer value if ((numericValue == Math.floor(numericValue)) && !Double.isInfinite(numericValue)) { //the number is an integer, this will remove the .0 trailing zeros int numericInt = numericValue.intValue(); valueField = String.valueOf(numericInt); } else { valueField = String.valueOf(cell.getNumericCellValue()); } break; case HSSFCell.CELL_TYPE_STRING: valueField = cell.getStringCellValue(); break; default: } return valueField; }
Example 7
Source File: XlsTable.java From Leo with Apache License 2.0 | 5 votes |
protected Object getDateValueFromJavaNumber(HSSFCell cell) { logger.debug("getDateValueFromJavaNumber(cell={}) - start", cell); double numericValue = cell.getNumericCellValue(); BigDecimal numericValueBd = new BigDecimal(String.valueOf(numericValue)); numericValueBd = stripTrailingZeros(numericValueBd); return new Long(numericValueBd.longValue()); // return new Long(numericValueBd.unscaledValue().longValue()); }
Example 8
Source File: POIUtils.java From ermaster-b with Apache License 2.0 | 5 votes |
public static int getIntCellValue(HSSFSheet sheet, int r, int c) { HSSFRow row = sheet.getRow(r); if (row == null) { return 0; } HSSFCell cell = row.getCell(c); if (cell.getCellType() != HSSFCell.CELL_TYPE_NUMERIC) { return 0; } return (int) cell.getNumericCellValue(); }
Example 9
Source File: readExcel.java From Selenium with The Unlicense | 5 votes |
private static String cellToString(HSSFCell cell) { Object result; switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: result = cell.getNumericCellValue(); break; case Cell.CELL_TYPE_STRING: result = cell.getStringCellValue(); break; case Cell.CELL_TYPE_BOOLEAN: result = cell.getBooleanCellValue(); break; case Cell.CELL_TYPE_FORMULA: result = cell.getCellFormula(); break; default: throw new RuntimeException("Unknown Cell Type"); } return result.toString(); }