fastexcel
fastexcel copied to clipboard
Can't decide between Date and Number cells
How can I decide if its a Date cell or just a number cell? I want to read different excel sheets, where I don't know which one is a date cell.
There is only a CellType Number and not a Date type. So I could try to read every number as Date, but than numbers will be read wrong for me, because they arent dates mostly.
So what I would expect is:
if (cell.getType() == CellType.Date)
{ cell.asDate(); }
else if(cell.getType() == CellType.Number)
{ cell.asNumber(); }
else
{ cell.getText(); }
Would be nice when smt. like this will work :)
Originally posted by @2knu in https://github.com/dhatim/fastexcel/issues/91#issuecomment-631576315
To achieve that, we would have to read the cell format (as replied in issue #91, date type does not exist) and apply complex checks (see DateUtil.isADateFormat()
) to verify it is actually a date format.
This is a lot of work.
I think it is an essential feature to know whether a cell actually contains a date or a number. I only just realised this was an issue and am now seriously considering using a different library, because without this ability, I cannot use fastexcel anymore.
dates are stored internally in Excel as double values, so I don't think adding something like CellType.Date
is possible.
With Apache POI, there's also no Date
type, but there's the method org.apache.poi.ss.usermodel.isCellDateFormatted
, which tells you if a cell is formatted as date. It would be great if fastexcel provides something similar.