Women in Technology

Hear us Roar



Article:
  Reading and Writing Excel Files with POI
Subject:   Reading Data From Excel using HSSFWorkbook +Java
Date:   2008-01-11 22:22:39
From:   SudheeshKumar
Hi,


when i am reading the date 11/1/2008 i am getting some integer values.I want to How to read Date field from excel and time (time is in yhe format 9:00


Thanks In advance
Sudheeh

Main Topics Oldest First

Showing messages 1 through 1 of 1.

  • Reading Data From Excel using HSSFWorkbook +Java
    2008-02-11 05:47:11  Kris... [View]

    This might solve your problem

    HSSFRow row = newXREFSheet.getRow(rowNo);
    if (row != null) {
    HSSFCell cell = row.getCell((short) col);
    if (cell != null) {
    switch (cell.getCellType()) {
    case HSSFCell.CELL_TYPE_NUMERIC:
    HSSFCellStyle style = cell.getCellStyle();
    if(style.getIndex() == 35){
    cellVal = cell.getDateCellValue().toString();
    String date = new SimpleDateFormat("MM/dd/yyyy").
    format(new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(cellVal.toString()));
    cellVal = date;
    }
    else{
    cellVal = String.valueOf(cell.getNumericCellValue());
    }
    break;
    case HSSFCell.CELL_TYPE_STRING:
    cellVal = cell.getStringCellValue();
    break;
    case HSSFCell.CELL_TYPE_FORMULA:
    cellValDoub = cell.getNumericCellValue();
    df = new DecimalFormat("##");
    cellVal = df.format(cellValDoub).toString();

    break;
    default:

    break;
    }
    }
    }