Hi Lorenzo
I've a similar problem (same country, same problems?). I need the german
JJMMTTTT but this is not an "official" excel format. For the moment I'm
writing the dates as strings because the customer doesn't want to compute
with the dates in Excel.
Anyway I've already written a method for converting Date-Objects in double
values that can be formatted as Date or Time in Excel. Maybe you can use it
(it's not tested much...).
Question: You're writing about POI 1.2.0. Isn't it 1.0.2? That's what I
downloaded 3 weeks ago from sourceforge.
Peter
/**
* Computes a double value which can be used for Excel date and time
formats.
*
* @param date date to be
* @return double value with integer part as days since 1.1.1900
* and fraction part as part of the day since midnight.
*/
public static double DateToDouble(Date date){
GregorianCalendar cal = new GregorianCalendar();
//may be we should set the timezone!
int leapyears = 0;
int years = 0;
int minutes = 0;
int seconds = 0;
double days = 0;
int SECONDS_PER_DAY = 24*60*60;
cal.setTime(date);
years = cal.get(GregorianCalendar.YEAR) - 1900;
for(int i=1900; i<cal.get(GregorianCalendar.YEAR); i++){
if (cal.isLeapYear(i)){
leapyears++;
}
}
days = cal.get(GregorianCalendar.DAY_OF_YEAR);
days += years*365 + leapyears + 1;
minutes = cal.get(GregorianCalendar.HOUR_OF_DAY)*60 +
cal.get(GregorianCalendar.MINUTE);
seconds = minutes * 60 + cal.get(GregorianCalendar.SECOND);
days = days + (double)seconds/SECONDS_PER_DAY;
return days;
}
-----Urspr�ngliche Nachricht-----
Von: Lorenzo Resta [mailto:[EMAIL PROTECTED]]
Gesendet: Freitag, 5. April 2002 11:55
An: '[EMAIL PROTECTED]'
Betreff: RE: Dates in Excel
Hi Lo�c,
Thanks for your answer. Is there a way in POI to get the format string that
Excel is using? The trouble is also, that i do not have under my control
what Version of Excel the customer is using. Since the customer is a large
international company, they use all different localized Excel versions you
can imagine :-(....
Best regards
Lorenzo
-----Original Message-----
From: Lo�c Lef�vre [mailto:[EMAIL PROTECTED]]
Sent: Freitag, 5. April 2002 11:55
To: [EMAIL PROTECTED]
Subject: RE: Dates in Excel
Hi,
Well I can tell you that I've the same problems as you:
-1- I can't use French formats (eg: 'j' intead of 'd' for day)
-2- I can't use / create my own format like mmmm\-yyyy for example
AFAIK, it's related to the localization of POI that is not internationalised
yet.
For the first problem, you can use the english formats (though they can not
give you satisfaction)
but for the second problem, you'll need to wait (perhaps) for the next
version of POI :(
Hope this helps.
Loic
-----Message d'origine-----
De : Lorenzo Resta [mailto:[EMAIL PROTECTED]]
Envoy� : vendredi 5 avril 2002 11:36
� : 'Poi-User (E-mail)
Objet : Dates in Excel
Hi,
Just a question on Dates in Excel. Since dates are not properly supported
yet (in POI 1.20) , i have to check the format number with
getCellStyle().getDataFormat(). This works fine, as long as people use the
Date specific formatttings in Excel. But whenever someone uses a custom
format like 'JJJJMM', where as 'J' stands for 'Year' and 'M' stands for
'Month', things get very unreliable, since the format number that Excel uses
in this case varies from 169 -178. Additionally Excel seems to use the same
format numbers also for non-date related custom formats, so things get very
nasty at this point, since i can' t properly figure out what is a date and
what not. Has someone an idea, how to handle such custom formatted dates
correctly in POI?
Thanks a lot
Lorenzo