[英]Validating the excel date for MM/dd/yyyy format
I am using Apache POI to read Excel file(.xlsx) and validate its contents. 我正在使用Apache POI读取Excel文件(.xlsx)并验证其内容。 We are having a date field in excel whcih should be in format MM/dd/yyyy.
我们在excel中有一个日期字段,格式应为MM / dd / yyyy。
Suppose if the date fild has two values as follows, 假设date fild具有以下两个值,
1) 04/24/2014 2) 04242014 1)2014年4月24日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.
由于excel以整数格式存储这两个值,因此我无法区分它们。 Please suggest if you have any idea about how to solve this.
请提出您是否有关于如何解决此问题的想法。
Apache POI allows to check data format of the cell with: Apache POI允许使用以下命令检查单元的数据格式:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.