From 0497e8c7ea75c5455c4daf79089f5d427e441833 Mon Sep 17 00:00:00 2001 From: Christian Holm Date: Mon, 27 Mar 2017 21:58:53 +0200 Subject: [PATCH 1/2] Support error references in cell ranges --- lib/utils/col-cache.js | 15 +++++++-------- spec/unit/utils/col-cache.spec.js | 1 + 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/utils/col-cache.js b/lib/utils/col-cache.js index 359154760..5070a0358 100644 --- a/lib/utils/col-cache.js +++ b/lib/utils/col-cache.js @@ -165,15 +165,12 @@ var colCache = module.exports = { // convert [sheetName!][$]col[$]row[[$]col[$]row] into address or range structures decodeEx: function(value) { - var sheetName; + var groups = value.match(/((('(([^']|'')*)')|([^'^ ^!]*))!)?(.*)/); - var parts = value.split('!'); - if (parts.length > 1) { - value = parts.pop(); - sheetName = parts.join('!').replace(/^'|'$/g, ''); - } + var sheetName = groups[4] || groups[6]; + var reference = groups[7]; - parts = value.split(':'); + var parts = reference.split(':'); if (parts.length > 1) { var tl = this.decodeAddress(parts[0]); var br = this.decodeAddress(parts[1]); @@ -192,8 +189,10 @@ var colCache = module.exports = { br: { address: br, col: right, row: bottom, $col$row: '$' + this.n2l(right) + '$' + bottom, sheetName: sheetName }, dimensions: tl + ':' + br }; + } else if (reference.startsWith('#')) { + return sheetName ? {sheetName: sheetName, error: reference} : {error: reference}; } else { - var address = this.decodeAddress(value); + var address = this.decodeAddress(reference); return sheetName ? Object.assign({sheetName: sheetName}, address) : address; } }, diff --git a/spec/unit/utils/col-cache.spec.js b/spec/unit/utils/col-cache.spec.js index c2af55eef..87725c2ec 100644 --- a/spec/unit/utils/col-cache.spec.js +++ b/spec/unit/utils/col-cache.spec.js @@ -72,6 +72,7 @@ describe('colCache', function() { expect(colCache.decodeEx('Sheet1!$H$1')).to.deep.equal({'$col$row':'$H$1', address:'H1', col:8, row:1, sheetName:'Sheet1'}); expect(colCache.decodeEx("'Sheet 1'!$H$1")).to.deep.equal({'$col$row':'$H$1', address:'H1', col:8, row:1, sheetName:'Sheet 1'}); expect(colCache.decodeEx("'Sheet !$:1'!$H$1")).to.deep.equal({'$col$row':'$H$1', address:'H1', col:8, row:1, sheetName:'Sheet !$:1'}); + expect(colCache.decodeEx("'Sheet !$:1'!#REF!")).to.deep.equal({sheetName:'Sheet !$:1', error:'#REF!'}); }); }); From f6d6907d1d3a6bf67b6d8376940c2245594742e5 Mon Sep 17 00:00:00 2001 From: Christian Holm Date: Tue, 28 Mar 2017 09:30:42 +0200 Subject: [PATCH 2/2] Add non-capturing groups to simplify a bit --- lib/utils/col-cache.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/utils/col-cache.js b/lib/utils/col-cache.js index 5070a0358..892e9dabb 100644 --- a/lib/utils/col-cache.js +++ b/lib/utils/col-cache.js @@ -165,10 +165,10 @@ var colCache = module.exports = { // convert [sheetName!][$]col[$]row[[$]col[$]row] into address or range structures decodeEx: function(value) { - var groups = value.match(/((('(([^']|'')*)')|([^'^ ^!]*))!)?(.*)/); + var groups = value.match(/(?:(?:(?:'((?:[^']|'')*)')|([^'^ ^!]*))!)?(.*)/); - var sheetName = groups[4] || groups[6]; - var reference = groups[7]; + var sheetName = groups[1] || groups[2]; // Qouted and unqouted groups + var reference = groups[3]; // Remaining address var parts = reference.split(':'); if (parts.length > 1) {