[prev in list] [next in list] [prev in thread] [next in thread] 

List:       poi-user
Subject:    Problem exporting date in POI
From:       Shirish Amin <amin () us ! ibm ! com>
Date:       2006-05-31 22:43:06
Message-ID: OFC36AFE1B.65017B63-ON8525717F.00791302-8525717F.007CA282 () us ! ibm ! com
[Download RAW message or body]

--=_alternative 007CA1DC8525717F_=
Content-Type: text/plain; charset="US-ASCII"

I am working on a project that exports data from a database to an Excel 
file.  I am having a problem exporting the dates.

The dates are stored as Java long value in the database.  I am creating a 
Date object from the long value.  When this Date object is written to a 
cell that is formatted with the HSSFDataFormat(0x16) ("m/d/yy h:mm"), the 
output date/time in Excel file is four hours ahead.  It appears that the 
HSSFCell.setCellValue(Date date) API is automatically converting the time 
to the GMT time.  Don't know if I am doing something wrong.

Is there a way to stop this automatic conversion?  If not, does anyone 
have a suggestion to work around this problem?

Here is the code snippet:

        HSSFCellStyle _dateStyle = createCellStyleForDate(wb, false);
        private HSSFCellStyle createCellStyleForDate(HSSFWorkbook 
workbook, boolean wrapText)
        {
                HSSFCellStyle dateStyle =  workbook.createCellStyle();

 dateStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
                dateStyle.setWrapText(wrapText);
                dateStyle.setDataFormat((short) 
HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm")); // custom format

            return dateStyle;
        }

        HSSFRow row = sheet.createRow(1);
        HSSFCell startTimeCell  = row.createCell(5);
        startTimeCell.setCellStyle(_dateStyle);

        Date startDate = new Date(objective.getStartTime());    // 
getStartTime() returns a long value
        startTimeCell.setCellValue(startDate);

I will appreciate any help on this problem.

Shirish
amin@us.ibm.com
--=_alternative 007CA1DC8525717F_=--
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic