Custom Number Format with "cellText: false, cellDates: true" broken #2349
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#2349
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?
File
sheetjs-bug.xlsx
Problem
Date
column is standard date format,Custom Date
column is custom formatwhen
XLSX.read
setcellDates: true
3542d62fff/bits/67_wsxml.js (L453)
fmtid
is30
, andSSF.is_date
gotundefined
so brokenDiscussion
SSF.is_date
validate input and returnfalse
for unexpected input.safe_is_date
likesafe_format
withSSFImplicit
table, and add more implicit format.workbook.Sheets
still includes the broken worksheet, just remove the broken cell.ECMA-376 (XLSX) does not specify a default for code 30, hence nothing is in the SSFImplicit table. It further states:
There are some locale-specific overrides for that particular code:
XLSB (2.5.76 Ifmt) refers to XLSX
XLS (2.4.126 Format) is even stranger, not prescribing a default for 30 and stating
Out of curiosity, can you repeat that process and save the file in a few different formats, namely "Excel 97-2003 Workbook (.xls)" and "SYLK (Symbolic Link) (.slk)"?
For *.xls,
SSF.is_date(SSF._table[fmtid] || String(fmtid))
will skip fmt 30 and read as normal number3542d62fff/bits/76_xls.js (L92)
For *.slk, the behavior is opposite to *.xls.
Custom date format can be recognized but normal date format cant.
Certainly, ECMA-376 not includes code 30, number format to string should be implementation-defined.
I just considering whether to add these special cases when
cellDates: true
, these values should be converted toDate
.We'd have to test across a few more locales. If Excel is always treating format code 30 as the default date format, we can just add it to SSFImplicit.
Can you share the SLK file? You may need to compress as ZIP and attach.
😉Request for an extra help, I want to know which custom format code should be recognized as
Date
, is there any specs to read ?Many thanks!
sheetjs-bug.slk.zip
Thanks!
The function is a stripped down version of the tokenizer https://github.com/SheetJS/ssf/blob/master/bits/81_fmttype.js#L3
It looks for the following date tokens:
B1
andB2
(calendar system)Y
andE
(year and era)M
,D
,H
,S
(month/minute, day, hour, second)A/P
,AM/PM
,上午/下午
(12-hour indicator)Can you check what version of the library you are using (
console.log(XLSX.version)
) ?With 0.17.0 setting cellDates: true generates dates for every cell:
With
cellNF: true
it looks like the format for cell B2 is missed (so something is still incorrect):My options:
Addtional: I'm using
xlsx
inWorker
.Ok finally i find
cellText: false
will cause this error.cellText: true
cellText: false
333deae63f/bits/11_ssfutils.js (L27)
333deae63f/bits/66_wscommon.js (L93-L94)
SSFImplicit
already includesfmt30
, but whencellText: false
, it won't be used.