Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading date value from excel cell as a String

I am using apache poi library to read excel file. I am stuck while reading password cell. If user gives date as a password in password cell i.e. 16/05/2012. I am reading this value as "41045" while value should be "16/05/2012". This is my code :

cell = row.getCell(); // date in the cell password '16/05/2012'
switch (cell.getCellType()) {

case HSSFCell.CELL_TYPE_STRING:
    cellValue = cell.getRichStringCellValue().getString();
    break;
case HSSFCell.CELL_TYPE_NUMERIC:
    if(cellCount == TEMPLATE_PASSWORD) {// if cell is password
        cell.setCellType(Cell.CELL_TYPE_STRING);
        cellValue = cell.getRichStringCellValue().getString(); // value read is 41045 and not "16/05/2012"
    }
    break;
default:
}

can anyone help on this?

Thanks.

like image 478
Nandkumar Tekale Avatar asked May 16 '12 10:05

Nandkumar Tekale


1 Answers

Use the below code to get the exact date formate as u entered in excel sheet.

DataFormatter df = new DataFormatter();
stringCellValue = df.formatCellValue(cell);
like image 163
user3044855 Avatar answered Oct 06 '22 02:10

user3044855