Boolean value parsing

This commit is contained in:
SheetJS 2013-03-04 18:27:31 -05:00
parent ba7b24a5d6
commit b275e4d4b5
2 changed files with 9 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{
"name": "xlsx",
"version": "0.0.8",
"version": "0.0.9",
"author": "Niggler",
"description": "(one day) a full-featured XLSX parser and writer. For now, primitive parser",
"keywords": [

14
xlsx.js
View File

@ -121,12 +121,13 @@ function parseSheet(data) { //TODO: use a real xml parser
case 'n': p.v = parseFloat(p.v); break;
case 's': p.v = strs[parseInt(p.v, 10)].t; break;
case 'str': break; // normal string
case 'b':
//Parse a boolean.
//I'm not sure how robust this method is.
p.v = Boolean(p.v);
break;
default: throw "Unrecognized cell type [" + p.t + "] with value: " + p.v;
case 'b':
switch(p.v) {
case '0': case 'FALSE': case "false": case false: p.v=false; break;
case '1': case 'TRUE': case "true": case true: p.v=true; break;
default: throw "Unrecognized boolean: " + p.v;
} break;
default: throw "Unrecognized cell type: " + p.t;
}
//s.cells[cell.r] = p;
s[cell.r] = p;
@ -396,6 +397,7 @@ function sheet_to_csv(sheet) {
switch(val.t){
case 'n': return val.v;
case 's': case 'str': return JSON.stringify(val.v);
case 'b': return val.v ? "TRUE" : "FALSE";
default: throw 'unrecognized type ' + val.t;
}
};