@Override public double getNumericCellValue() { return _cell.getNumericCellValue(); } @Override
/** * Get the value of the cell as a date. * For strings we throw an exception. * For blank cells we return a null. * See {@link HSSFDataFormatter} for formatting * this date into a string similar to how excel does. */ public Date getDateCellValue() { if (_cellType == CellType.BLANK) { return null; } double value = getNumericCellValue(); if (_book.getWorkbook().isUsing1904DateWindowing()) { return HSSFDateUtil.getJavaDate(value, true); } return HSSFDateUtil.getJavaDate(value, false); }
return sdf.format(getDateCellValue()); return String.valueOf(getNumericCellValue()); case STRING: return getStringCellValue();
case NUMERIC: HSSFCellStyle style = cell.getCellStyle(); double nVal = cell.getNumericCellValue(); short df = style.getDataFormat(); String dfs = style.getDataFormatString();
break; case Cell.CELL_TYPE_NUMERIC: newCell.setCellValue(oldCell.getNumericCellValue()); break; case Cell.CELL_TYPE_STRING:
frec.getFormulaRecord().setValue(getNumericCellValue()); if (setValue) nrec.setValue(getNumericCellValue());
@Override public double getNumericCellValue() { return _cell.getNumericCellValue(); } @Override
public double getNumericCellValue() { return _cell.getNumericCellValue(); } public int getRowIndex() {
@Test public void test_Should_be_0() throws Exception { HSSFCell cell = new HSSFWorkbook().createSheet().createRow(0).createCell(0); cell.setCellValue(0); Assert.assertTrue(cell.getNumericCellValue() == 0);
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()); }
@Test public void test_Should_be_0() throws Exception { HSSFCell cell = new HSSFWorkbook().createSheet().createRow(0).createCell(0); cell.setCellValue(0); HSSFCell cell2 = new HSSFWorkbook().createSheet().createRow(0).createCell(0); cell2.setCellValue(0); Assert.assertTrue(cell.getNumericCellValue() == cell2.getNumericCellValue());
HSSFCell cellE1 = row1.getCell((short) 4); cellE1.setCellType(HSSFCell.CELL_TYPE_NUMERIC); Double e1Val = cellE1.getNumericCellValue(); BigDecimal bd = new BigDecimal(e1Val.toString()); long lonVal = bd.longValue(); System.out.println(lonVal);
InputStream myxls = new FileInputStream("workbook.xls"); wb = new HSSFWorkbook(myxls); sheet = wb.getSheetAt(0); // first sheet row = sheet.getRow(0); // third row HSSFCell cell = (HSSFCell) row.getCell((short)1); // fourth cell if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) { System.out.println("The Cell was a String with value \" " + cell.getStringCellValue()+" \" "); } else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) { System.out.println("The cell was a number " + cell.getNumericCellValue()); } else { System.out.println("The cell was nothing we're interested in"); }
public static double getCellValue(HSSFCell cell){ switch (cell.getCachedFormulaResultType()){ case Cell.CELL_TYPE_NUMERIC: return cell.getNumericCellValue(); break; case Cell.CELL_TYPE_STRING: return Double.parse(cell.getStringCellValue()); break; default: throw new RuntimeException("Data type not applicable"); } }
public Integer Check4(int b) throws IOException { InputStream myxls = new FileInputStream("book.xls"); HSSFWorkbook wb = new HSSFWorkbook(myxls); HSSFSheet sheet = wb.getSheetAt(0); // first sheet HSSFRow row = sheet.getRow(1); // first row //HSSFCell cell0 = row.getCell((short)a); // first arg HSSFCell cell1 = row.getCell((short)b); // second arg String sell = cell1.toString(); cell1.setCellType(HSSFCell.CELL_TYPE_NUMERIC); System.out.println("smth "+ (int) Math.round(cell1.getNumericCellValue())); return (int) Math.round(cell1.getNumericCellValue()); }
private String getValueFromColumn(HSSFRow row, int i) { try { return new Integer(new Double(row.getCell((short) i).getNumericCellValue()).intValue()).toString(); } catch (NumberFormatException e) { return row.getCell((short) i).getStringCellValue(); } catch (IllegalStateException e) { return row.getCell((short) i).getStringCellValue(); } }
private String getValueFromColumn(HSSFRow row, int i) { try { return new Integer(new Double(row.getCell((short) i).getNumericCellValue()).intValue()).toString(); } catch (NumberFormatException e) { return row.getCell((short) i).getStringCellValue(); } catch (IllegalStateException e) { return row.getCell((short) i).getStringCellValue(); } }
private Voxel3DGrid createGrid(HSSFSheet descriptionSheet, ReferenceFrame gridFrame) { int numberOfVoxelsPerDimension = (int) descriptionSheet.getRow(2).getCell(1).getNumericCellValue(); double voxelSize = descriptionSheet.getRow(3).getCell(2).getNumericCellValue(); int numberOfRaysPerVoxel = (int) descriptionSheet.getRow(4).getCell(2).getNumericCellValue(); int numberOfRotationsPerRay = (int) descriptionSheet.getRow(5).getCell(2).getNumericCellValue(); SphereVoxelShape sphereVoxelShape = new SphereVoxelShape(gridFrame, voxelSize, numberOfRaysPerVoxel, numberOfRotationsPerRay, SphereVoxelType.graspOrigin); return new Voxel3DGrid(gridFrame, sphereVoxelShape, numberOfVoxelsPerDimension, voxelSize); }
private Voxel3DGrid createGrid(HSSFSheet descriptionSheet, ReferenceFrame gridFrame) { int numberOfVoxelsPerDimension = (int) descriptionSheet.getRow(2).getCell(1).getNumericCellValue(); double voxelSize = descriptionSheet.getRow(3).getCell(2).getNumericCellValue(); int numberOfRaysPerVoxel = (int) descriptionSheet.getRow(4).getCell(2).getNumericCellValue(); int numberOfRotationsPerRay = (int) descriptionSheet.getRow(5).getCell(2).getNumericCellValue(); SphereVoxelShape sphereVoxelShape = new SphereVoxelShape(gridFrame, voxelSize, numberOfRaysPerVoxel, numberOfRotationsPerRay, SphereVoxelType.graspOrigin); return new Voxel3DGrid(gridFrame, sphereVoxelShape, numberOfVoxelsPerDimension, voxelSize); }
private Object getCellValue(HSSFCell cell) { if (cell == null) { return null; } if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) { switch (cell.getCachedFormulaResultType()) { case Cell.CELL_TYPE_NUMERIC: return cell.getNumericCellValue(); case Cell.CELL_TYPE_STRING: return cell.getStringCellValue().replaceAll("'", ""); } } return null; }