From dd1d98d1421f7fb30393986837aef85fb07dfdc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wulf=20S=C3=B6lter?= Date: Fri, 17 Jun 2016 14:55:50 +1200 Subject: [PATCH] Fall back to JSON.stringify() if unknown Cell.Type --- lib/doc/cell.js | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/lib/doc/cell.js b/lib/doc/cell.js index 88a800d0e..775e02290 100644 --- a/lib/doc/cell.js +++ b/lib/doc/cell.js @@ -733,14 +733,50 @@ SharedStringValue.prototype = { } }; +var JSONValue = function(cell, value) { + this.model = { + address: cell.address, + type: Cell.Types.SharedString, + value: value + }; +}; +JSONValue.prototype = { + get value() { + return this.model.value; + }, + set value(value) { + return this.model.value = value; + }, + get type() { + return Cell.Types.SharedString; + }, + get effectiveType() { + return Cell.Types.SharedString; + }, + get address() { + return this.model.address; + }, + set address(value) { + return this.model.address = value; + }, + toCsvString: function() { + return '' + JSON.stringify(this.model.value); + }, + release: function() { + }, + toString: function() { + return JSON.stringify(this.model.value); + } +}; + // Value is a place to hold common static Value type functions var Value = { getType: function(value) { if ((value === null) || (value === undefined)) { return Cell.Types.Null; - } else if ((value instanceof String) || (typeof value == 'string')) { + } else if ((value instanceof String) || (typeof value === 'string')) { return Cell.Types.String; - } else if (typeof value == 'number') { + } else if (typeof value === 'number') { return Cell.Types.Number; } else if (value instanceof Date) { return Cell.Types.Date; @@ -753,8 +789,9 @@ var Value = { } else if (value.sharedString) { return Cell.Types.SharedString; } else { + return Cell.Types.JSON; //console.log('Error: value=' + value + ', type=' + typeof value) - throw new Error('I could not understand type of value: '); + // throw new Error('I could not understand type of value: ' + JSON.stringify(value) + ' - typeof: ' + typeof value); } }, @@ -767,6 +804,7 @@ var Value = { {t:Cell.Types.Hyperlink, f:HyperlinkValue}, {t:Cell.Types.Formula, f:FormulaValue}, {t:Cell.Types.Merge, f:MergeValue}, + {t:Cell.Types.JSON, f:JSONValue}, {t:Cell.Types.SharedString, f:SharedStringValue}, {t:Cell.Types.RichText, f:RichTextValue} ].reduce(function(p,t){p[t.t]=t.f; return p;}, []),