Try using,
HSSFDataFormat.getFormat("dd/MM/yyyy");
mm --> denotes minutes in time format. So, for months
we need to use "MM".
Hope it works.
Regards,
Lakshmi
--- Sancho Chiang <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am currently writing an API for writing list of
> objects into excel worksheet.
> POI works great but when it comes to appending data
> to an existing worksheet,
> existing custom data format cannot be applied to the
> cells. I found that the
> indexes of the existing custom format ain't properly
> mapped.
>
> I drilled into the source code and I got to the line
> which I guess it's the
> source of the problem.
>
> at HSSFDataFormat.getFormat(String)line:235
> --> formats.add( ind, i.next() );
>
> I am new to POI and not familiar with the source
> code. I guess what the above
> code does is to populate the builtin data format
> into "formats", where custom
> formats are already in there. Since it is using
> add(), the existing custom
> formats are pushed to the right of the list if the
> given index is smaller than
> those existing custom formats. That messes up the
> mapping between index and
> data format. I don't know whether it's the problem
> of my code or a known bug. I
> hope some guys who are nice enough to clarify the
> problem. Thx.
>
> This is the code i used:
> public static void testDataFormat()throws
> Exception{
> InputStream input = new
> FileInputStream("players.xls");
> POIFSFileSystem fs = new POIFSFileSystem(input);
> HSSFWorkbook wb = new HSSFWorkbook(fs);
> HSSFSheet sheet = wb.getSheet("Sheet1");
> HSSFRow row =
> sheet.createRow(sheet.getLastRowNum()+1);
> HSSFCell cell = row.createCell((short)0);
> HSSFCellStyle cellStyle= wb.createCellStyle();
> HSSFDataFormat dataFormat = wb.createDataFormat();
> short format = dataFormat.getFormat("dd/mm/yyyy");
> System.out.println("excelFormat::"+format);
> cellStyle.setDataFormat(format);
> cell.setCellStyle(cellStyle);
> cell.setCellValue(new Date());
>
> FileOutputStream fileOut = new
> FileOutputStream("players.xls");
> wb.write(fileOut);
> fileOut.close();
> }
>
> Regards,
> Sancho Chiang
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> Mailing List:
> http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta Poi Project:
> http://jakarta.apache.org/poi/
>
>
__________________________________
Yahoo! Mail Mobile
Take Yahoo! Mail with you! Check email on your mobile phone.
http://mobile.yahoo.com/learn/mail
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/