This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
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: 41634
    
  55
Welcome to JavaRanch.

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


Ping & DNS - my free Android networking tools app
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);
 
wood burning stoves
 
subject: Populate a date field in excel as dateformat instead of string using Java