简体   繁体   中英

how to get date cell value as it is from excel using apache poi (without formatting)

In my excel, I have date like: 在此处输入图像描述

but when reading it, it is printing as 11/30/22, ie it is printing in mm/dd/yy format but I need value as it is in excel cell, I tried different way but either it is giving in double or in this format. Can you please help, how can i fetch the cell value as it is..

Below are few approaches I tried so far:

   DataFormatter df = new DataFormatter();
   Cell sDate = row.getCell(1);

   1) FormulaEvaluator formeval = new XSSFFormulaEvaluator((XSSFWorkbook) workbook);
     String startDate = df.formatCellValue(sDate,formeval);
     print (startDate);

   2) String startDate = df.formatCellValue(sDate);
     print (startDate);
 
   3) print ( sDate.getNumericCellValue());

Excel stores dates as sequential serial numbers so that they can be used in calculations. By default, January 1, 1900 is serial number 1, and January 1, 2008 is serial number 39448 because it is 39,447 days after January 1, 1900.

Link

You have to format it by yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM