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

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

问题描述

我正在使用 Apache POI 读取 Excel 文件 (.xlsx) 并验证其内容.我们在 excel 中有一个日期字段,其格式应为 MM/dd/yyyy.

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) 2014 年 4 月 24 日2) 04242014

1) 04/24/2014 2) 04242014

我必须接受第一个并拒绝第二个.由于 excel 以整数格式存储这两个值,因此我无法区分它们.如果您对如何解决此问题有任何想法,请提出建议.

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 允许检查单元格的数据格式:

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

第二:

true
DDMMYYYY

这篇关于验证 MM/dd/yyyy 格式的 Excel 日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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