preserve type and number format for empty cells #1711

Closed
opened 2019-12-23 02:58:19 +00:00 by aimergenge · 7 comments
aimergenge commented 2019-12-23 02:58:19 +00:00 (Migrated from github.com)
please reopen https://github.com/SheetJS/sheetjs/issues/1691 This is a demo file: [各厂投保率保费报表(2019年12月31日).xlsx](https://github.com/SheetJS/sheetjs/files/3993492/2019.12.31.xlsx)
aimergenge commented 2019-12-23 03:00:26 +00:00 (Migrated from github.com)

And this is my code:

const workbook = read(uint8array, {
    type: 'array',
    cellHTML: false,
    sheetStubs: true,
    cellNF: true
})
And this is my code: ```js const workbook = read(uint8array, { type: 'array', cellHTML: false, sheetStubs: true, cellNF: true }) ```
SheetJSDev commented 2019-12-23 03:00:37 +00:00 (Migrated from github.com)

Which cell is missing format?

Which cell is missing format?
aimergenge commented 2019-12-23 03:01:03 +00:00 (Migrated from github.com)

@SheetJSDev For example D4

@SheetJSDev For example `D4`
SheetJSDev commented 2019-12-23 03:07:17 +00:00 (Migrated from github.com)

Thanks for reporting, you're right and we'll accept a PR with the following change:

diff --git a/bits/66_wscommon.js b/bits/66_wscommon.js
index 38b2db5..b4278fc 100644
--- a/bits/66_wscommon.js
+++ b/bits/66_wscommon.js
@@ -85,11 +85,11 @@ function get_cell_style(styles/*:Array<any>*/, cell/*:Cell*/, opts) {
 }
 
 function safe_format(p/*:Cell*/, fmtid/*:number*/, fillid/*:?number*/, opts, themes, styles) {
-       if(p.t === 'z') return;
-       if(p.t === 'd' && typeof p.v === 'string') p.v = parseDate(p.v);
        try {
                if(opts.cellNF) p.z = SSF._table[fmtid];
        } catch(e) { if(opts.WTF) throw e; }
+       if(p.t === 'z') return;
+       if(p.t === 'd' && typeof p.v === 'string') p.v = parseDate(p.v);
        if(!opts || opts.cellText !== false) try {
                if(SSF._table[fmtid] == null) SSF.load(SSFImplicit[fmtid] || "General", fmtid);
                if(p.t === 'e') p.w = p.w || BErr[p.v];
Thanks for reporting, you're right and we'll accept a PR with the following change: ```diff diff --git a/bits/66_wscommon.js b/bits/66_wscommon.js index 38b2db5..b4278fc 100644 --- a/bits/66_wscommon.js +++ b/bits/66_wscommon.js @@ -85,11 +85,11 @@ function get_cell_style(styles/*:Array<any>*/, cell/*:Cell*/, opts) { } function safe_format(p/*:Cell*/, fmtid/*:number*/, fillid/*:?number*/, opts, themes, styles) { - if(p.t === 'z') return; - if(p.t === 'd' && typeof p.v === 'string') p.v = parseDate(p.v); try { if(opts.cellNF) p.z = SSF._table[fmtid]; } catch(e) { if(opts.WTF) throw e; } + if(p.t === 'z') return; + if(p.t === 'd' && typeof p.v === 'string') p.v = parseDate(p.v); if(!opts || opts.cellText !== false) try { if(SSF._table[fmtid] == null) SSF.load(SSFImplicit[fmtid] || "General", fmtid); if(p.t === 'e') p.w = p.w || BErr[p.v]; ```
aimergenge commented 2019-12-23 03:12:05 +00:00 (Migrated from github.com)

Thanks, so what can I help now?

Thanks, so what can I help now?
reviewher commented 2019-12-23 03:23:40 +00:00 (Migrated from github.com)

We just cut the 0.15.4 release, please update and try :)

We just cut the 0.15.4 release, please update and try :)
aimergenge commented 2019-12-23 03:33:56 +00:00 (Migrated from github.com)

It works! Thx!

It works! Thx!
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#1711
No description provided.