java XSSF POI 是单元格日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6677326/
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
XSSF POI is cell date
提问by Zemzela
Is there a way to determine if cell is a date? I know about style.getDataFormatString() but that doesn't help me, because I can't determine if is formating is for date or not.
有没有办法确定单元格是否是日期?我知道 style.getDataFormatString() 但这对我没有帮助,因为我无法确定格式化是否针对日期。
回答by Gagravarr
If you're using the XSSF UserModel, then you want DateUtil.isCellDateFormatted(Cell)- this will return a boolean telling you if the format string for the cell represents a data or not.
如果您使用 XSSF UserModel,那么您需要DateUtil.isCellDateFormatted(Cell)- 这将返回一个布尔值,告诉您单元格的格式字符串是否表示数据。
If you're down at the low level XML stuff, you need DateUtil.isADateFormat(int,String)instead. The style ID comes from the cell xml. The style string you'll have to get out of the styles table, which is a different Package Part. There are helpers for loading that though
如果您在低级别的 XML 内容上失败,则需要DateUtil.isADateFormat(int,String)代替。样式 ID 来自单元格 xml。您必须从样式表中取出的样式字符串,它是一个不同的包部件。有帮助加载虽然
You probably want to look at XSSFExcelExtractorDecorator from Tikafor an example of doing the latter - it does formatting of cells from an event parsing.
您可能想查看Tika 的 XSSFExcelExtractorDecorator以获取执行后者的示例 - 它从事件解析中格式化单元格。
回答by Evan
cell.getCellTypeEnum() == CellType.NUMERIC && DateUtil.isCellDateFormatted(cell)
cell.getCellTypeEnum() == CellType.NUMERIC && DateUtil.isCellDateFormatted(cell)