File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes Populate a date field in excel as dateformat instead of string using Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Populate a date field in excel as dateformat instead of string using Java" Watch "Populate a date field in excel as dateformat instead of string using Java" New topic
Author

Populate a date field in excel as dateformat instead of string using Java

Saravana Kumar Arumugam
Greenhorn

Joined: Mar 29, 2007
Posts: 1
I need to populate a date field in excel as date format instead of string using Java. I tried using POI API & HSSF date style, but the date is getting populated as general format only. Please help me out to populate the data as a date field as I�m using the value to manipulate many other fields in the sheet to generate charts in Excel.



Thanks and Regards,

Saravana
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42950
    
  72
Welcome to JavaRanch.

Isn't that what HSSFDataFormat with a date format (like Oxe to Ox16) is supposed to do?
Anjana Ravindran
Ranch Hand

Joined: Aug 22, 2005
Posts: 76
Hi,
I am also trying to help him in solving the issue.

It is the code he tried...
To create a new style for date


HSSFCellStyle dateStyle = null;

dateStyle = workbook.createCellStyle();

dateStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("mm/dd/yy"));


and then for populating �Created Date� cell I used the below code,


cell = row.createCell((short) 3);
cell.setCellValue(new Date());
cell.setCellStyle(dateStyle);
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Populate a date field in excel as dateformat instead of string using Java