验证MM / dd / yyyy格式的excel日期 [英] Validating the excel date for MM/dd/yyyy format
问题描述
我正在使用Apache POI读取Excel文件(.xlsx)并验证其内容。
我们在excel中有一个日期字段,应该是格式为MM / dd / yyyy。假设日期fild有两个值,如下所示:
1)04/24/2014
2)04242014
我必须接受第一个并拒绝第二个。
由于excel将这两个值以整数格式存储,我无法区分它们。
如果您有任何关于如何解决这个问题的建议,请咨询。
Apache POI允许使用以下方式检查单元格的数据格式:
的System.out.println(HSSFDateUtil.isCellDateFormatted(小区));
System.out.println(cell.getCellStyle()。getDataFormatString());
为您的第一个单元格提供:
true
DD\ / MM\ / YYYY
和第二个:
true
pre>
DDMMYYYY
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
这篇关于验证MM / dd / yyyy格式的excel日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!