简体   繁体   English

XSSF POI 是单元格日期

[英]XSSF POI is cell date

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() 但这对我没有帮助,因为我无法确定格式化是否适用于日期。

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) - 这将返回一个 boolean 告诉您单元格的格式字符串是否代表数据。

If you're down at the low level XML stuff, you need DateUtil.isADateFormat(int,String) instead.如果你在低级别 XML 东西,你需要DateUtil.isADateFormat(int,String)代替。 The style ID comes from the cell xml.样式 ID 来自单元格 xml。 The style string you'll have to get out of the styles table, which is a different Package Part.您必须从 styles 表中取出样式字符串,该表是不同的 Package 部分。 There are helpers for loading that though虽然有加载的助手

You probably want to look at XSSFExcelExtractorDecorator from Tika for an example of doing the latter - it does formatting of cells from an event parsing.您可能想查看Tika 的 XSSFExcelExtractorDecorator以获取后者的示例 - 它从事件解析中格式化单元格。

cell.getCellTypeEnum() == CellType.NUMERIC && DateUtil.isCellDateFormatted(cell) cell.getCellTypeEnum() == CellType.NUMERIC && DateUtil.isCellDateFormatted(cell)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM