How to read Excel cell having Date with Apache POI?

前端 未结 8 2342
面向向阳花
面向向阳花 2020-11-28 03:57

I\'m using Apache POI 3.6, I want to read an excel file which has a date like this 8/23/1991.

 switch (cell.getCellType()) {

   ...
   ...

            


        
8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 04:41

    Yes, I understood your problem. If is difficult to identify cell has Numeric or Data value.

    If you want data in format that shows in Excel, you just need to format cell using DataFormatter class.

    DataFormatter dataFormatter = new DataFormatter();
    String cellStringValue = dataFormatter.formatCellValue(row.getCell(0));
    System.out.println ("Is shows data as show in Excel file" + cellStringValue);  // Here it automcatically format data based on that cell format.
    // No need for extra efforts 
    

提交回复
热议问题