简体   繁体   中英

Validating the excel date for MM/dd/yyyy format

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.

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

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