Validating the excel date for MM/dd/yyyy format

冷暖自知 提交于 2019-12-25 02:26:14

问题


I am using Apache POI to read Excel file(.xlsx) and validate its contents. We are having a date field in excel whcih should be in format MM/dd/yyyy.

Suppose if the date fild has two values as follows,

1) 04/24/2014 2) 04242014

I have to accept the first one and reject the second. Since excel stores both these values in integer format, I am not able to differentiate them. Please suggest if you have any idea about how to solve this.


回答1:


Apache POI allows to check data format of the cell with:

System.out.println(HSSFDateUtil.isCellDateFormatted(cell));
System.out.println(cell.getCellStyle().getDataFormatString());

which gives for your first cell:

true
DD\/MM\/YYYY

and for second:

true
DDMMYYYY


来源:https://stackoverflow.com/questions/23306067/validating-the-excel-date-for-mm-dd-yyyy-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!