Reply to topic  [ 2 posts ] 
Passing dates to EasyXLS 
Author Message

Joined: Wed May 09, 2007 8:36 am
Posts: 14
Location: Israel
Reply with quote
Post Passing dates to EasyXLS
Hi!

I wanted to pass a date to Excel using EasyXLS. I used the following code:

Code:
Calendar c1 = Calendar.getInstance();
c1.setTime(date1);
int d1 = c1.get(Calendar.DAY_OF_MONTH);
int m1 = c1.get(Calendar.MONTH);
int y1 = c1.get(Calendar.YEAR);
            
xlsTable.easy_getCell(2,0).setValue("" + y1);
xlsTable.easy_getCell(2,1).setValue("" + m1);
xlsTable.easy_getCell(2,2).setValue("" + d1);


I then put the following formula in an excel cell
=DATE(A3,B3,C3)

Is there a better method?


Sun Jul 01, 2007 10:22 am
Profile

Joined: Fri Feb 03, 2006 12:23 pm
Posts: 199
Location: Brasov, Romania
Reply with quote
Post 
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");
---------------------------


Tue Jul 03, 2007 2:30 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.