0

I am trying to get a date from an Excel cell using Java Apache POI library.

The field contains a date 30.1.2019 12:00:00 and I've selected d.m.yyyy h:mm as format string for that cell. When I loop over the Excel sheet with apache POI, it reports the call as of type CellType.NUMERIC and returns value 43495.5.

I have no idea what to do with that number. It's too small for it to be seconds since UNIX epoch.

Noteworthy: When I open the file in MS Excel and change the cell's format to normal number, I also see 43495.5 directly in Excel. So the value probably has meaning, I just don't know how to parse it.

Maybe I'm just doing it wrong. How to get the date from Excel via Apache POI, ideally as java.util.Date?

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
  • 2
    Do using `DataFormatter` as shown in [Getting the cell contents](https://poi.apache.org/components/spreadsheet/quick-guide.html#CellContents) to avoid such problems. Else you needs switching by `CellType` as also shown in linked users guide. Btw.: Yes the number has meaning. It is 43495.5 days after 01/01/1900. – Axel Richter Feb 04 '19 at 12:14

1 Answers1

1

Excel converts the date with a datavalue function which returns a serial number. A solution was already given: How to read Excel cell having Date with Apache POI?

TheCurl
  • 106
  • 1
  • 2