EasyXLS http://forum.easyxls.com/ |
|
Passing dates to EasyXLS http://forum.easyxls.com/viewtopic.php?f=5&t=50 |
Page 1 of 1 |
Author: | teniel [ Sun Jul 01, 2007 10:22 am ] | |||||||||
Post subject: | Passing dates to EasyXLS | |||||||||
Hi! I wanted to pass a date to Excel using EasyXLS. I used the following code:
I then put the following formula in an excel cell =DATE(A3,B3,C3) Is there a better method? |
Author: | daniela [ Tue Jul 03, 2007 2:30 am ] |
Post subject: | |
If you want to keep the calendar, here is a sample. You need to set also the cell data type: ------------------------- Calendar c1 = Calendar.getInstance(); c1.setTime(date1); int d1 = c1.get(Calendar.DAY_OF_MONTH); int m1 = c1.get(Calendar.MONTH)+1; int y1 = c1.get(Calendar.YEAR); xlsTable.easy_getCell("A3").setValue(m1+"/"+d1+"/"+y1); xlsTable.easy_getCell("A3").setDataType(DataType.DATE); --------------------------- Another possible solution is to use the SimpleDateFormat for formatting your date: --------------------------- java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("MM/dd/yyyy"); xlsTable.easy_getCell("A3").setValue(sdf.format(date1)); xlsTable.easy_getCell("A3").setDataType(DataType.DATE); --------------------------- The best solution is to store the entire date (also the hours, minutes and seconds) and apply a date format for the cell: --------------------------- java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); xlsTable.easy_getCell("A3").setValue(sdf.format(date1)); xlsTable.easy_getCell("A3").setFormat("MM/dd/yyyy"); --------------------------- |
Page 1 of 1 | All times are UTC - 4 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |