question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Number Format with "cellText: false, cellDates: true" broken

See original GitHub issue

File

sheetjs-bug.xlsx

Problem

Date column is standard date format, Custom Date column is custom format image

image

when XLSX.read set cellDates: true https://github.com/SheetJS/sheetjs/blob/3542d62fffc155dd505a23230ba182c4402a0e2c/bits/67_wsxml.js#L453 fmtid is 30, and SSF.is_date got undefined so broken image

Discussion

  1. SSF.is_date validate input and return false for unexpected input.
  2. use safe_is_date like safe_format with SSFImplicit table, and add more implicit format.
  3. not broken whole worksheet, because workbook.Sheets still includes the broken worksheet, just remove the broken cell.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
woshiguabicommented, Aug 11, 2021

Can you check what version of the library you are using (console.log(XLSX.version)) ?

image

My options:

XLSX.read(ev.data.arrayBuffer, {
    type: 'array',
    cellFormula: false,
    cellHTML: false,
    cellText: false,
    cellStyles: true,
    cellDates: true,
    sheetRows: 100000,
    WTF: true,
}),

Addtional: I’m using xlsx in Worker.

Ok finally i find cellText: false will cause this error.

cellText: true

// SSF._table
{
    "0": "General",
    "1": "0",
    "2": "0.00",
    "3": "#,##0",
    "4": "#,##0.00",
    "9": "0%",
    "10": "0.00%",
    "11": "0.00E+00",
    "12": "# ?/?",
    "13": "# ??/??",
    "14": "m/d/yy",
    "15": "d-mmm-yy",
    "16": "d-mmm",
    "17": "mmm-yy",
    "18": "h:mm AM/PM",
    "19": "h:mm:ss AM/PM",
    "20": "h:mm",
    "21": "h:mm:ss",
    "22": "m/d/yy h:mm",
    "30": "m/d/yy", // added fmtid 30 in _table
    "37": "#,##0 ;(#,##0)",
    "38": "#,##0 ;[Red](#,##0)",
    "39": "#,##0.00;(#,##0.00)",
    "40": "#,##0.00;[Red](#,##0.00)",
    "45": "mm:ss",
    "46": "[h]:mm:ss",
    "47": "mmss.0",
    "48": "##0.0E+0",
    "49": "@",
    "56": "\"上午/下午 \"hh\"時\"mm\"分\"ss\"秒 \"",
    "176": "[$-F800]dddd\\,\\ mmmm\\ dd\\,\\ yyyy"
}

cellText: false

// SSF._table
{
    "0": "General",
    "1": "0",
    "2": "0.00",
    "3": "#,##0",
    "4": "#,##0.00",
    "9": "0%",
    "10": "0.00%",
    "11": "0.00E+00",
    "12": "# ?/?",
    "13": "# ??/??",
    "14": "m/d/yy",
    "15": "d-mmm-yy",
    "16": "d-mmm",
    "17": "mmm-yy",
    "18": "h:mm AM/PM",
    "19": "h:mm:ss AM/PM",
    "20": "h:mm",
    "21": "h:mm:ss",
    "22": "m/d/yy h:mm",
    "37": "#,##0 ;(#,##0)",
    "38": "#,##0 ;[Red](#,##0)",
    "39": "#,##0.00;(#,##0.00)",
    "40": "#,##0.00;[Red](#,##0.00)",
    "45": "mm:ss",
    "46": "[h]:mm:ss",
    "47": "mmss.0",
    "48": "##0.0E+0",
    "49": "@",
    "56": "\"上午/下午 \"hh\"時\"mm\"分\"ss\"秒 \"",
    "176": "[$-F800]dddd\\,\\ mmmm\\ dd\\,\\ yyyy"
}

https://github.com/SheetJS/sheetjs/blob/333deae63fbe13d1ff2db42e599211a062001c32/bits/11_ssfutils.js#L27

https://github.com/SheetJS/sheetjs/blob/333deae63fbe13d1ff2db42e599211a062001c32/bits/66_wscommon.js#L93-L94

SSFImplicit already includes fmt30, but when cellText: false, it won’t be used.

0reactions
woshiguabicommented, Aug 11, 2021

Can you check what version of the library you are using (console.log(XLSX.version)) ?

image

My options:

XLSX.read(ev.data.arrayBuffer, {
    type: 'array',
    cellFormula: false,
    cellHTML: false,
    cellText: false,
    cellStyles: true,
    cellDates: true,
    sheetRows: 100000,
    WTF: true,
}),

Addtional: I’m using xlsx in Worker.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Format date with SheetJS - javascript - Stack Overflow
I am trying to use SheetJS to read a .xlsx file but am having some trouble with a column of dates that is...
Read more >
7 Amazing Excel Custom Number Format Tricks (you Must ...
Using Excel Custom Number Formatting, you can display the data in the desired format. Here are six Excel Custom Number Format tricks for...
Read more >
xlsx - npm
The parser covers a wide gamut of common spreadsheet file formats to ensure that "HTML-saved-as-XLS" files work as well as actual XLS or...
Read more >
JS-XLSX Core Test Runner - SheetJS
should not generate number formats by default43ms ‣ ... should generate date cells if cellDates is true350ms ‣ ... should preserve custom properties ......
Read more >
XLSX avoid large numbers from converting to exponential with ...
In my xlsx sheet there is a date and number in sheet I am facing issue when I ... { type: "binary", cellText:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found