Java HSSF POI:如何知道单元格中的数据是否属于日期类型?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18307337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HSSF POI : How to know if data in cell is of Type Date?
提问by Abhishek Singh
Currently i have my code as
目前我有我的代码
bean.setREPO_DATE(row.getCell(16).getDateCellValue());
it works fine if cell is formatted as date in excel.
如果单元格格式为 excel 中的日期,它工作正常。
However it also converts some integer or long like 1234 or 5699 to date. I know the reason behind this too.
但是,它也会将一些整数或长整数(如 1234 或 5699)转换为日期。我也知道这背后的原因。
However i want to apply a check before executing above line. Something like this
但是我想在执行上述行之前应用检查。像这样的东西
if(row.getCell(16).isOfDateFormat){
bean.setREPO_DATE(row.getCell(16).getDateCellValue());
}
Please Guide me..
请指导我..
Thanks in Advance !
提前致谢 !
采纳答案by newuser
Try this,
尝试这个,
use import org.apache.poi.ss.usermodel.DateUtil;
用 import org.apache.poi.ss.usermodel.DateUtil;
if(DateUtil.isCellDateFormatted(cell))
{
cell.getDateCellValue();
}