Apache POI从xlsx文件读取日期

时间:2019-03-08 00:50:36

标签: java apache-poi

我正在尝试从xlsx文件中读取格式为“ 07/27/1955”的日期,但是日期不正确。我尝试过的每个日期都会返回eithe日期。

这是我在这里查看@Sayantam的答案后所得到的内容:https://stackoverflow.com/a/7261427/9659160

FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();

                    CellValue cValue = evaluator.evaluate(currCell);
                    double dv = cValue.getNumberValue();
                    if (DateUtil.isCellDateFormatted(currCell)) {
                        Date date = HSSFDateUtil.getJavaDate(dv);
                        String dateFmt = currCell.getCellStyle().getDataFormatString();
                        String strValue = new CellDateFormatter(dateFmt).format(date);
                        System.out.println(strValue);
                    }

当Excel文件中的07/27/1955时,它将返回6/20/04。

对于相同的值

currCell.getStringCellValue() 

返回20297

currCell.getDateCellValue() 

返回1904年6月20日星期一东部时间

currCell.getNumericCellValue() 

返回1633.0

0 个答案:

没有答案
相关问题