Hi, The Apache POI library will convert your java Date values directly if you use the setValue(java.util.Date value) or setCellValue(java.util.Calendar value).
You can also specify a formatter for the cell to control how Excell will display the date. POI is very easy to use to create XLS or XLSX document. Samuel > Le 28 nov. 2016 à 13:07, Theodore Petrosky <[email protected]> a écrit : > > So excel stores and expects to find date as an integer. The number of days > since 01-01-1900. > > I am trying to write out to excel and I have these dates. So is created a > method that calculates the number of days from 01-01-1900. My problem is that > I am two days off, so I adjusted the jan01 date two days. > > Does anyone know why it is two days off? the only thing I can think of is > that it is calculating the leap years incorrectly. every four years except > century years, and there are two century years here (1900 and 2000), > > public int dateAsInt() { > > SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); > > Date date = null; > try { > date = format.parse ( "1899-12-30" ); > } catch (ParseException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > > NSTimestamp jan011900 = new NSTimestamp(date); > > System.out.println(jan011900); > > long diff = eventDate().getTime() - jan011900.getTime(); // > diff is in milliseconds > long roundingOffset = ( diff >= 0 ) ? 12 : -12; // if diff is > positive, offset up, if negative, offset down > // next, convert diff to hours, offset by .5 days to round the > end result, divide by 24 and truncate. > long days = ( ( diff / ( 1000 * 60 * 60 ) ) + roundingOffset ) > / 24; > > return (int)days; > } > _______________________________________________ > Do not post admin requests to the list. They will be ignored. > Webobjects-dev mailing list ([email protected]) > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/webobjects-dev/samuel%40samkar.com > > This email sent to [email protected]
_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list ([email protected]) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to [email protected]
