You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Beppe Costagliola <be...@yahoo.it> on 2004/08/13 10:13:14 UTC

Time cell

How can I write a cell with a only time value (without the default java data of jan 1970) ?

Thanks.

Re: Time cell

Posted by Davinder Kohli <kd...@yahoo.com>.
Excel cannot handle time alone, it converts the time
to a datetime format, so if we had, say, 12:01:00 PM
HSSF converts that into java.sql.time, 12/31/1899
12:01:00 using
double excelDate =
HSSFDateUtil.getExcelDate((Time)cellValue);
theCell.setCellValue(excelDate);
Since HSSF does not handle dates prior to 1/1/1900 it
puts a bad date (-1). 
Therefore convert the time to string and setting the
time format.

theCell.setCellType(HSSFCell.CELL_TYPE_STRING);
if (cellValue != null){
  theCell.setCellValue(((Time)cellValue).toString());
} 				
// create the cell style using "h:mm:ss AM/PM" and set
it
theCell.setCellStyle(timeCellStyle);

I have not put in all the code, but this how you can
approach it.
Hope this helps.
 Davinder Kohli

--- Beppe Costagliola <be...@yahoo.it> wrote:

> How can I write a cell with a only time value
> (without the default java data of jan 1970) ?
> 
> Thanks.
> 



	
		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail 

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-user-help@jakarta.apache.org