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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 39547
    
  27
Welcome to JavaRanch.

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


Ping & DNS - updated with new look and Ping home screen widget
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);
 
 
subject: Populate a date field in excel as dateformat instead of string using Java
 
Similar Threads
servlets and sql
How can we know the date format when we get the data from EXCEL using JXL package
. reading data from MS EXcel using apache poi api
how to make different date format validation ?
Read Excel values and store in to Database