From 91f8c467041afd8071fb3a777ce38c389c4e6bdf Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 26 Apr 2020 02:02:58 -0500 Subject: [PATCH] HTML preserve cell number format --- bits/79_html.js | 9 ++++++--- test_files | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/bits/79_html.js b/bits/79_html.js index d652d5b..b616080 100644 --- a/bits/79_html.js +++ b/bits/79_html.js @@ -83,6 +83,7 @@ var HTML_ = (function() { sp.t = cell && cell.t || 'z'; if(o.editable) w = '' + w + ''; sp.id = (o.id || "sjs") + "-" + coord; + if(sp.t != "z") { sp.v = cell.v; if(cell.z != null) sp.z = cell.z; } oo.push(writextag('td', w, sp)); } var preamble = ""; @@ -105,8 +106,8 @@ var HTML_ = (function() { for(var R = r.s.r; R <= r.e.r; ++R) out.push(make_html_row(ws, r, R, o)); out.push("" + footer); return out.join(""); - } + } return { to_workbook: html_to_book, to_sheet: html_to_sheet, @@ -138,7 +139,8 @@ function parse_dom_table(table/*:HTMLElement*/, _opts/*:?any*/)/*:Worksheet*/ { for(_C = C = 0; _C < elts.length; ++_C) { var elt/*:HTMLTableCellElement*/ = elts[_C]; if (opts.display && is_dom_element_hidden(elt)) continue; - var v/*:string*/ = htmldecode(elt.innerHTML); + var v/*:string*/ = elt.hasAttribute('v') ? elt.getAttribute('v') : htmldecode(elt.innerHTML); + var z/*:string*/ = elt.getAttribute('z'); for(midx = 0; midx < merges.length; ++midx) { var m/*:Range*/ = merges[midx]; if(m.s.c == C && m.s.r <= R && R <= m.e.r) { C = m.e.c+1; midx = -1; } @@ -160,7 +162,8 @@ function parse_dom_table(table/*:HTMLElement*/, _opts/*:?any*/)/*:Worksheet*/ { o.z = opts.dateNF || SSF._table[14]; } } - if(opts.dense) { if(!ws[R]) ws[R] = []; ws[R][C] = o; } + if(o.z === undefined && z != null) o.z = z; + if(opts.dense) { if(!ws[R]) ws[R] = []; ws[R][C] = o;} else ws[encode_cell({c:C, r:R})] = o; if(range.e.c < C) range.e.c = C; C += CS; diff --git a/test_files b/test_files index a4155e4..f1780af 160000 --- a/test_files +++ b/test_files @@ -1 +1 @@ -Subproject commit a4155e4c17fbe2aba8a79ebe6c17d76f4277901e +Subproject commit f1780af21ee98d62278283b4a455a2a4a21b2889