开发者

XSSF POI is cell date

开发者 https://www.devze.com 2023-03-19 18:36 出处:网络
Is there a way to determine if cell is a date? I know about style.getDataFormatString() but that doesn\'t help me,

Is there a way to determine if cell is a date? I know about style.getDataFormatString() but that doesn't help me, beca开发者_如何学编程use I can't determine if is formating is for date or not.


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.

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

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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消