I am trying to upload and read contents of an Excel file. It works fine if the content is in String format. But my content in the excel file is as follows:
02:02:02
03:03:03
04:04:04
All I want to do is retrieve the content as it is. But when I pull this data over, I end up getting the content as follows:
8.4745370370370374E-2
0.12711805555555555
0.169490740740741
Is there any way around to not change the content?
while (rowIterator.hasNext())
{
Row row = rowIterator.next();
//For each row, iterate through all the columns
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext())
{
Cell cell = cellIterator.next();
cell.setCellType(Cell.CELL_TYPE_STRING);
//Check the cell type and format accordingly
switch (cell.getCellType())
{
case Cell.CELL_TYPE_NUMERIC:
System.out.print(cell.getNumericCellValue());
break;
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue());
break;
}
}
}
Your cell format is probably not set to Text. Check this out:
As you can see, when you do not explicit set the cell type to text, excel tries to guess it. So when you are importing it, it is probably importing as Time. You may read it as Text, by explicit setting the cell type to Text
and then typing the time 02:02:02
, or you may read it as excel Time format and then convert it. Find out more about reading excel dates: How to read Excel cell having Date with Apache POI? Reading date values from excel cell using POI HSSF API
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments