Support of cellDates #581
No reviewers
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#581
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "patch-1"
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?
Currently the
cellDates
option doesn't work and the Date cells are not correctly recognized.I propose a fix that returns
.d
that contains the JavaScript Date.I also propose to provide
fmt
andfmtid
to the object so the user will be able to deal with any customized formats. It will give more flexibility.What should
cellDates
do in general?The original intention of the
cellDates
option was to normalize files for some ECMA-376 logic. Excel generally writes files with dates stored as numbers (typen
) with the date code, but the spec technically allows for storing ISO date strings (typed
). The default behavior is to convert the date cells to numeric, but settingcellDates:true
preserves the native format. On the write side, the default behavior is to convert cell objects witht:"d"
to numeric cells. SettingcellDates:true
will save as XLSX date cells.Note to self: SpreadsheetML and ODS should also follow the option
The user should be able to know when the cell contains a date. Right now nothing permits to know that, or I didn't understand how to proceed?!
With the changes I did the intent is to indicate to the user that the cell contains a date and to parse it to the
.d
. So I'm opened to suggestions if you have another way to find this information.Also it looks important for the user to get the
fmt
in order to correctly treat the format of the content on his/her hand, don't you think?Thanks!
The
cellNF
option should expose the actual number format string to thez
field of the cell objects. For example with the test file https://github.com/sheetjs/test_files/blob/master/number_format.xlsm?raw=true cell B24 of sheet "Implied" is set to the format#,##0.00;[Red](#,##0.00)
:A quick comparison shows the same behavior for XLS and XLSB.
It does the same thing for the internal number formats, so you don't have to do a big switch on the format id -- you can just scan the string.
This should be something exposed by the
SSF
formatter, but you are right that the information is not available at the moment.Disregard my last comment. You want to proactively change number cells with a date format, and that's fine :)
Conclusion:
try using the
cellNF:true
option and reading the format from the.z
field of the cell. If that works, we should not try to expose the internal number format ID.I will change the format parser so that it tells you if it thinks the format is a date. Basically it would be a simplified form of the tokenizer
Your commit is good, but the simple regex doesn't handle cases like the custom format
0 "months"
(since the "m" is in quotation marks it's a literal character).Also, can you shoot an email to sheetjs@gmail.com -- the git log shows an anonymized address :/
Thanks for all these details. It helped me, and I'm now able to parse a date cell without modifying the original js-xlsx code by using
.z
withcellNF:true
! :-)I know the way to parse the format is not perfect, but it should work in most cases for now.
This is for my ExcelPlus library that I use as an interface of js-xslx to easily manipulate an Excel file.
@SheetJSDev I'm having issues getting a value in z on date objects coming in from an
xls
formatted file. They seem to just not be there...ropts= { type: 'binary', cellNF: true }
is what I'm using (doing this all client side/in browser) - wondering if the file type I'm using or the binary flag is interfering with z value parsing or if you have any advice. Alternatively two columns will always have this formatting - and I think I should be able to manually transform the epoch into a normal date format and manually set the format as I walk it into xlsx, but hoping to avoid that.@reidblomquist if you aren't seeing cell formats, that's a bug in the library.
I just checked against an XLS file with a cell encoding a date and it appears to populate the data for dates:
(note: the whole concept of the "date cell" type is specific to XLSX -- XLSB and XLS do not have a date cell type and always represent dates as numeric cells)
Can you share a file where
cellNF
is not adding formats to a cell? If you don't want to make it public, you can email us at dev@sheetjs.com@SheetJSDev before I do that, I'm going to pull down the sheet that test uses and run it through my code. Would you also mind running a check using { type: 'binary' } in addition to cellNF true - wondering if that combo is what's causing. Thanks! Also, you could very well be right that my source sheet has something going on - since it's being generated by some ruby code (hahahaha)
@SheetJSDev disregard! it is indeed an issue with formatting in the sheet my Ruby code is generating haha. Man sheet inception. Thanks again for being so prompt! Lmk if you want me to delete some of my comments on here to clean it up - and thanks for your hard work/awesome free software!
@reidblomquist It's probably best to move this discussion to a new issue, as it is somewhat unrelated to the core issue of this PR and @Aymkdn probably doesn't want to see all of these unrelated notifications!
If you are generating a file that does the right thing in Excel (formats a cell properly) but not with js-xlsx, it's a bug in js-xlsx and I recommend raising a new issue with that file.
If your generated file isn't doing the right thing in Excel, then clearly your file generation process has an issue.
@SheetJSDev last comment here - but yes it does seem to be something with the file generation for the xls I'm reading from - I'll do some testing to confirm my findings but so far I'm thinking it has to do with the date not being formatted with traditional / delineators but with . notation. When I open my source xls file they're shown as Date types in excel, but if I re-select that format it reformats the cells to use / delineators and if I then run that "fixed" xls file through js-xlsx everything works as expected. If you'd like me to pull together some sample code and files and open up a new issue I'd be more than happy to!
@reidblomquist yes that sounds like a different sort of bug in js-xlsx, so a new issue with a test file or some sample code would be appreciated :) Once you raise that issue, I will go back and clean up these comments
@Aymkdn we added an
is_date
helper to SSF, factored out of the eval function.Next version will have this fix and will ensure consistent
cellDates
handlingAwesome !!! Thank you 👍
We expect to push the next release sometime this week
Pull request closed