Reputation: 30092
I am using the Office JS API to interact with a spreadsheet. I am reading a series of values from a sheet without knowing the expected data types in advance.
How can I determine whether a value is a date? Date values are returned as numeric values, so it's difficult to make the determination. The best way I've found so far is to interrogate the numberFormat
property and check if the format is "date-like", however it's a bit flimsy.
Is there any built in way using the API to have it report to me that it's a date?
Upvotes: 1
Views: 235
Reputation: 23540
Excel does not have a native Date or Time or Currency data type - so there is no reliable way of determining if a cell is supposed to be a date. Using NumberFormat is probably the best you can do from JavaScript
In the VBA and COM-Interop APIs Range.Value returns a date or currency data type for cells formatted as dates or currency, and Range.Value2 always returns a double regardless of formatting.
Upvotes: 1