Retain original date format in sheet_to_json #2628
Labels
No Label
DBF
Dates
Defined Names
Features
Formula
HTML
Images
Infrastructure
Integration
International
ODS
Operations
Performance
PivotTables
Pro
Protection
Read Bug
SSF
SYLK
Style
Write Bug
good first issue
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sheetjs/sheetjs#2628
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I know there are a lot of similar issues, but I've not found one that solves my problem and I have the feeling is might not be possible...
A user uploads an xlsx document, and one of the columns is a date, and it's displayed as "25/03/1981"
I'd like to configure sheet_to_json so it returns "25/03/1981" as a string. Ie, return exactly as how it's being displayed in Excel.
I've tried many different configurations, and can't get it to work - it'll return in the format "MM/DD/YYYY", or days since the epoch, or as a JS Date stamp, but not the original format.
Note: I cannot use dateNF: "DD/MM/YYYY" to format after, as I don't know in advance what format they are uploading.
Eg, they could upload an xlsx document with dates such as "1981-03-26 12:00"
Any ideas?
Thanks
raw: false
will use the formatted value. The default will use the raw value. https://docs.sheetjs.com/#jsonThanks for replying.
I've tried that but for the file attached, it returns US format (mm/dd/yyyy) rather than UK format (dd/mm/yyyy).
UAT_dataset1.xlsx
Output:
Code:
@reviewher how can I re-open this ticket? Thank you.
Has anyone got an idea why I can't the dates as formatted in the sheet?
I've uniziped the XLSX file and looked at the style sheet and realised the issue is to do with the number format
numFmtId="14"
.Apparently OpenXML / ECMA-376 (edition 1) gives the wrong date format for format code 14.
More here: https://github.com/SheetJS/sheetjs/issues/181
and here: https://social.msdn.microsoft.com/Forums/office/en-US/e27aaf16-b900-4654-8210-83c5774a179c/xlsx-numfmtid-predefined-id-14-doesnt-match?forum=oxmlsdk
Date code 14 is localized, see https://github.com/SheetJS/sheetjs/issues/326 for more details. The
dateNF
option was added as a workaround, but the real solution is to ship tables for each relevant locale (or try to speculate usingIntl
)