apache poi add .0 on a number code example

Example: apache poi add .0 on a number

InputStream inp =getClass().getResourceAsStream("filename.xls"));
Workbook wb = WorkbookFactory.create(inp);
DataFormatter objDefaultFormat = new DataFormatter();
FormulaEvaluator objFormulaEvaluator = new HSSFFormulaEvaluator((HSSFWorkbook) wb);

Sheet sheet= wb.getSheetAt(0);
Iterator<Row> objIterator = sheet.rowIterator();

while(objIterator.hasNext()){

  Row row = objIterator.next();
  Cell cellValue = row.getCell(0);
  objFormulaEvaluator.evaluate(cellValue); // This will evaluate the cell, And any type of cell will return string value
  String cellValueStr = objDefaultFormat.formatCellValue(cellValue,objFormulaEvaluator);

}

Tags:

Misc Example