From fa6a55ffbea0f5b665654a1c8b6858eac0f500ca Mon Sep 17 00:00:00 2001 From: Yves Le Maout Date: Tue, 27 May 2014 15:37:05 +0200 Subject: [PATCH 1/2] Correct indentation --- xlsx.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xlsx.js b/xlsx.js index 07913f8..9b82089 100644 --- a/xlsx.js +++ b/xlsx.js @@ -1831,8 +1831,8 @@ function write_sty_xml(wb, opts) { o.push(XML_HEADER); o.push(STYLES_XML_ROOT); if((w = write_numFmts(wb.SSF))) o.push(w); - o.push(''); - o.push(''); + o.push(''); + o.push(''); o.push(''); o.push(''); if((w = write_cellXfs(opts.cellXfs))) o.push(w); From 131fa7d0342f838d78e0941a1a78f717d5a2b3b2 Mon Sep 17 00:00:00 2001 From: Yves Le Maout Date: Wed, 28 May 2014 10:17:29 +0200 Subject: [PATCH 2/2] Handle shared formulas Retrieve shared formulas according to ECMA-376, Part 1, 18.3.1.40 f (Formula) --- xlsx.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/xlsx.js b/xlsx.js index 9b82089..fe7e562 100644 --- a/xlsx.js +++ b/xlsx.js @@ -2167,7 +2167,7 @@ function parse_ws_xml(data, opts, rels) { } var refguess = {s: {r:1000000, c:1000000}, e: {r:0, c:0} }; - var q = (opts.cellFormula ? ["v","f"] : ["v"]); + var refFormula = {}; var sidx = 0; /* 18.3.1.80 sheetData CT_SheetData ? */ @@ -2188,7 +2188,32 @@ function parse_ws_xml(data, opts, rels) { var cell = parsexmltag((c.match(/]*>/)||[c])[0]); delete cell[0]; var d = c.substr(c.indexOf('>')+1); var p = {}; - q.forEach(function(f){var x=d.match(matchtag(f));if(x)p[f]=unescapexml(x[1]);}); + + // Parse the tag value + var x = d.match(matchtag("v")); + if(x) { p.v = unescapexml(x[1]); } + + /* 18.3.1.40 f (Formula) */ + if (opts.cellFormula) { + var x = d.match(matchtag("f")); + if(x) { + p.f = unescapexml(x[1]); + var formulaTag = parsexmltag(x[0]); + if (formulaTag.t === 'shared' && formulaTag) { + formulaTag.f = p.f; + refFormula[formulaTag.si] = formulaTag; + } + } else if (d.indexOf(" -1) { + var formulaRefTag = d.match(/]*>/); + if (formulaRefTag) { + formulaRefTag = parsexmltag(formulaRefTag[0]); + if (formulaRefTag && formulaRefTag.t === 'shared' && refFormula[formulaRefTag.si]) { + p.f = refFormula[formulaRefTag.si].f; + } + } + } + } + /* SCHEMA IS ACTUALLY INCORRECT HERE. IF A CELL HAS NO T, EMIT "" */ if(cell.t === undefined && p.v === undefined) { if(!opts.sheetStubs) return;