I catch my cells from an .xls file like this:
cell.getStringCellValue();
But since some of the cells are numeric, I have to do this instead:
try
{
cells[colIx] = cell.getStringCellValue();
} catch (IllegalStateException e)
{
cells[colIx] = String.valueOf(cell.getNumericCellValue());
}
since it's getting a double and then converts it to a string this results in some unwanted operations like:
- 1 converts into 1.0 (not that kind of a big problem)
- 16711680 converts to 1.671168E7
How do I solve this and get the actual cell value instead of some converted numbers? Also, all of the cells are defined as default in excel
try using cell.getCellType() as you have
You can use Apache POI
DataFormatter
'sformatCellValue(Cell cell)
method as it returns the formatted value of a cell as a String regardless of the cell type.According to DataFormatter doc -
Sample code