You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by anish <mn...@gmail.com> on 2010/11/17 11:19:48 UTC
to read date content from an excel file
Hi All,
I am facing diffculty in reading date content from an excel file.
If the cell data i.e date is not formatted according to excel.
It is converted into double value.
Here is my code i have done
if (cell == null)
return value;
switch (cell.getCellType()) {
case Cell.CELL_TYPE_FORMULA:
value = "" + cell.getCellFormula();
break;
case Cell.CELL_TYPE_NUMERIC:
if (DateUtil.isCellDateFormatted(cell)) {
value = "" + cell.getDateCellValue();
}
else
{
value =""+cell.getNumericCellValue();
}
//value = cell.getStringCellValue();
break;
case Cell.CELL_TYPE_STRING:
value = cell.getStringCellValue();
break;
case Cell.CELL_TYPE_BOOLEAN:
value = "" + cell.getBooleanCellValue();
break;
default:
}
Is they any mechanism to get date value with out being converted to double
it can be in any format.
Thanks & Regards
anish
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/to-read-date-content-from-an-excel-file-tp3268820p3268820.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: to read date content from an excel file
Posted by Mark Beardsley <ma...@tiscali.co.uk>.
Have a look at the DataFormatter class -
http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/DataFormatter.html
- and more specifically at the formatCelValue() method(s). They will accept
as a parameter a ference yo a cell from the worksheet and return to you a
formatted String containing - in your case - the date value you are looking
for.
Yours
Mark B
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/to-read-date-content-from-an-excel-file-tp3268820p3269296.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org