Quantcast

Apache POI - Excel Custom Date Formats

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Apache POI - Excel Custom Date Formats

vishwak
Gernating an Excel SpreadSheet..

I am unable to set the date format to a Cell in Excel
to dd.mmm.yyyy. Are custom date formats supported in
Apache POI? The foll. piece of code seems to work only
when the input DATE_FORMAT is one of the built-in
formats mentioned in the docs, else it is displayed as
a numeric value.

HSSFCell cell = getCell(workSheet, row, col);
cell.setCellValue((Date) value);
HSSFCellStyle cellStyle = workBook.createCellStyle();
     
cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat(DATE_FORMAT));
               
cell.setCellStyle(cellStyle);

Can Someone tell me or guide me in the right
direction?


thanks,
Vishwa


      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page.
http://www.yahoo.com/r/hs

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Apache POI - Excel Custom Date Formats

Nick Burch
On Fri, 1 Feb 2008, Vishwa Kumba wrote:
> HSSFCell cell = getCell(workSheet, row, col);
> cell.setCellValue((Date) value);
> HSSFCellStyle cellStyle = workBook.createCellStyle();
>
> cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat(DATE_FORMAT));

You'll probably want to create a custom DataFormat -
workbook.createDataFormat(), the use that to add your custom format
string, and finally use that on the cell styles

See http://poi.apache.org/hssf/quick-guide.html#DataFormats

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...