When I try and print out the content in a cell containing a number with five decimal places, the number is automatically rounded off to 3 d.p. This is what I have so far:
Cell cellNum = sheet1.getCell(col,row);
WritableCell cell = sheet1.getWritableCell(col, row);
if (cell.getType() == CellType.NUMBER){
cellNum = sheet1.getCell(col,row);
NumberFormat fivedps = new NumberFormat("#.#####");
WritableCellFormat cellFormat = new WritableCellFormat(fivedps);
cell.setCellFormat(cellFormat);
String cellContent = cellNum.getContents();
System.out.print(cellContent + "\t");
}
else{
// Cell cellNum = sheet1.getCell(col,row);
String cellContent = cellNum.getContents();
System.out.print(cellContent + "\t");
After checking for the Cell type and if it is of type number, then cast the Cell to NumberCell for reading it's value. For the example you shared, it should be something like this:
if (cell.getType() == CellType.NUMBER){
NumberCell cellNum = (NumberCell) sheet1.getCell(col,row);
System.out.println(cellNum.getValue()); //this will return a double value
}
You can use similar techniques to read other values such as Date by casting it to DateCell. Hope this helps!