poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "jakub kuzela" <poimaill...@gmail.com>
Subject Re: read custom format date hh:mm:ss:00�
Date Mon, 14 Apr 2008 11:28:22 GMT
Hi,

if you want create cell with format hh:mm:ss.00 u can do this:

     HSSFCellStyle cellData = wb.createCellStyle();
     HSSFDataFormat formatData = wb.createDataFormat();
     cellData.setDataFormat(formatData.getFormat("hh:mm:ss.00"));

     HSSFWorkbook wb = new HSSFWorkbook();
     HSSFSheet sheet = wb.createSheet("new sheet");
     HSSFRow row = sheet.createRow((short)0);

     cell = row.createCell((short)1);
     cell.setCellStyle(cellStyle);
     java.util.Date utilDate = new java.util.Date();
     cell.setCellValue(utilDate);

if you want read this cell back you can do this:

    InputStream inp = new FileInputStream("D:/workbook.xls");

    wb = new HSSFWorkbook(new POIFSFileSystem(inp));
    sheet = wb.getSheet("new sheet");
    row = sheet.getRow((short)0);
    cell = row.getCell((short)1);

    java.util.Date readDate = cell.getDateCellValue();
    System.out.println("DATE IS: "+readDate);

Is this what you ask?

Jakub.



2008/4/14, Nick Burch <nick@torchbox.com>:
>
> On Fri, 11 Apr 2008, mariag wrote:
>
> > I am new to this HSSF. I have an urgent requirement to read an excel
> > file.
> > But it has a time field that I don't know how to read it.
> >
> > Can anyone please help me in reading a date cell with excel custom
> > format hh\:mm\:ss.00? if I have the value in the cell as 00.00.18.13,excel is displaying
itas 12:00:18 AM.
> >
>
> I'm not sure quite what you're after, but have you tried reading:
>        http://poi.apache.org/hssf/quick-guide.html#CreateDateCells
>        http://poi.apache.org/hssf/quick-guide.html#DataFormats
> ?
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message