krish420
krish420

Reputation: 5

java apache poi date format and blank cell handling

XSSFWorkbook workbook07 = new XSSFWorkbook(xlname);                     
XSSFSheet sheet1 = workbook07.getSheet(sheetname);
CellReference cvalue = new CellReference("E11"); 
Row nrow = sheet1.getRow(cvalue.getRow());
Cell cell = (nrow.getCell(cvalue.getCol());

when am trying to get a date value of 1/9/2009 from a cell means, its returning it in some format like 1-oct-2009. i need to get the exact format of the date what ever in the cell, and print it as a output ..that means i need out put as 1/9/2009.

and i have to ask one more, using this if am trying to get a blankcell values its returning null.pointer exception .. its returning exception while getting the values itself so i cont able to handle it

Cell cell = (nrow.getCell(cvalue.getCol());

so i can't able handle it like this

if {cell.Cell_TYPE_}

can any one plz help me out..!!

Upvotes: 0

Views: 2056

Answers (1)

Gagravarr
Gagravarr

Reputation: 48366

If you know the cell is really a Date cell (and not a String cell where someone has typed in a date by hand as a String), just call Cell.getDateCellValue() and you'll get back a Java Date object

You can also use DateUtil.isCellDateFormatted(cell) if you want to check if a cell is a date one or not (Excel doesn't have a specific type for date cells, they're just number cells with special formatting rules)

Upvotes: 1

Related Questions