验证MM / dd / yyyy格式的excel日期 [英] Validating the excel date for MM/dd/yyyy format

查看:228
本文介绍了验证MM / dd / yyyy格式的excel日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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 
DDMMYYYY
pre>

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆