Cells' Date format issue when saving a file as CSV #2515
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#2515
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
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?
SCENARIO: our reactjs app has an option to export the same data source as .CSV file or as a .XLSX file. Data source (JSON array) is identical in both cases and the same method is doing the export logic for both file types.
Before a file is finally exported, I'm formatting certain columns based on the settings provided, such that I'm setting certain columns' formats to type DATE with a specific date formatting style - so something like this =>
where
dateCellFormat
is =>const dateCellFormat = 'm/d/yy';
ISSUE: when saving a file as .XLSX file then date formatting is correctly applied to cells that I'm targeting, but when saving that same data source as .CSV it is not.
In the case of .XLSX file, when I open it in excel, it says that the cell's format is of type DATE (with m/d/yy formatting applied correctly), so that works as intended, but when I open the .CSV export in excel, then it says that the cell's format is of type CUSTOM (with m/d/yyyy h:mm formatting applied, which seems like a bug to me since nowhere in code am I applying such formatting).
Once again, json data source is the SAME for both file types and the same method is doing the export logic for both file types.
QUESTION: is there something that I'm missing ? Should I format cells in some different fashion when exporting to .csv or did I just find a bug ?
Can't reproduce: https://jsfiddle.net/vh7son9z/
It generates both the XLSX and the CSV file. Opening the CSV file looks like:
Thanks to your comment now I see what I forgot to outline in my original post, the cell's v (value) is not of type Date , but actually, a string containing a date. And that's where the bug happens.
So if you cast it to Date, and set the cell's value to that, then it works in both file types, but if you pass Date formatted as a string, then your code only works in XLS, but not in CSV . This is confusing, at least, if a certain cell formatting logic works in xls , it should work in csv as well, right ? Thanks for your feedback once again
I updated your fiddle so that you can see what I'm talking about (you'll see that it displays as intended in xls file, but not in csv file) : https://jsfiddle.net/4xfuL9rz/