Skip to content

Fall back to JSON.stringify() if unknown Cell.Type #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions lib/doc/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
},

Expand All @@ -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;}, []),
Expand Down