2014-01-28 16:38:02 +00:00
|
|
|
/* 18.3 Worksheets */
|
2014-02-07 10:53:40 +00:00
|
|
|
function parse_ws_xml(data, opts) {
|
2014-01-28 16:38:02 +00:00
|
|
|
if(!data) return data;
|
|
|
|
/* 18.3.1.99 worksheet CT_Worksheet */
|
|
|
|
var s = {};
|
|
|
|
|
|
|
|
/* 18.3.1.35 dimension CT_SheetDimension ? */
|
|
|
|
var ref = data.match(/<dimension ref="([^"]*)"\s*\/>/);
|
|
|
|
if(ref && ref.length == 2 && ref[1].indexOf(":") !== -1) s["!ref"] = ref[1];
|
|
|
|
|
|
|
|
var refguess = {s: {r:1000000, c:1000000}, e: {r:0, c:0} };
|
|
|
|
var q = ["v","f"];
|
|
|
|
var sidx = 0;
|
|
|
|
/* 18.3.1.80 sheetData CT_SheetData ? */
|
|
|
|
if(!data.match(/<sheetData *\/>/))
|
|
|
|
data.match(/<sheetData>([^\u2603]*)<\/sheetData>/m)[1].split("</row>").forEach(function(x) {
|
|
|
|
if(x === "" || x.trim() === "") return;
|
|
|
|
|
|
|
|
/* 18.3.1.73 row CT_Row */
|
|
|
|
var row = parsexmltag(x.match(/<row[^>]*>/)[0]);
|
|
|
|
if(refguess.s.r > row.r - 1) refguess.s.r = row.r - 1;
|
|
|
|
if(refguess.e.r < row.r - 1) refguess.e.r = row.r - 1;
|
|
|
|
|
|
|
|
/* 18.3.1.4 c CT_Cell */
|
2014-01-29 06:00:09 +00:00
|
|
|
var cells = x.substr(x.indexOf('>')+1).split(/<c /);
|
2014-01-28 16:38:02 +00:00
|
|
|
cells.forEach(function(c, idx) { if(c === "" || c.trim() === "") return;
|
2014-02-05 13:39:21 +00:00
|
|
|
var cref = c.match(/r=["']([^"']*)["']/);
|
2014-01-29 06:00:09 +00:00
|
|
|
c = "<c " + c;
|
2014-01-28 16:38:02 +00:00
|
|
|
if(cref && cref.length == 2) {
|
|
|
|
var cref_cell = decode_cell(cref[1]);
|
|
|
|
idx = cref_cell.c;
|
|
|
|
}
|
|
|
|
var cell = parsexmltag((c.match(/<c[^>]*>/)||[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]);});
|
|
|
|
|
|
|
|
/* SCHEMA IS ACTUALLY INCORRECT HERE. IF A CELL HAS NO T, EMIT "" */
|
2014-02-07 10:53:40 +00:00
|
|
|
if(cell.t === undefined && p.v === undefined) {
|
2014-02-12 06:09:42 +00:00
|
|
|
if(!opts.sheetStubs) return;
|
2014-02-07 10:53:40 +00:00
|
|
|
p.t = "str"; p.v = undefined;
|
|
|
|
}
|
2014-01-28 16:38:02 +00:00
|
|
|
else p.t = (cell.t ? cell.t : "n"); // default is "n" in schema
|
2014-02-07 10:53:40 +00:00
|
|
|
if(refguess.s.c > idx) refguess.s.c = idx;
|
|
|
|
if(refguess.e.c < idx) refguess.e.c = idx;
|
2014-02-15 05:08:18 +00:00
|
|
|
/* 18.18.11 t ST_CellType */
|
2014-01-28 16:38:02 +00:00
|
|
|
switch(p.t) {
|
|
|
|
case 'n': p.v = parseFloat(p.v); break;
|
|
|
|
case 's': {
|
|
|
|
sidx = parseInt(p.v, 10);
|
|
|
|
p.v = strs[sidx].t;
|
|
|
|
p.r = strs[sidx].r;
|
2014-02-12 06:09:42 +00:00
|
|
|
if(opts.cellHTML) p.h = strs[sidx].h;
|
2014-01-28 16:38:02 +00:00
|
|
|
} break;
|
2014-01-29 06:00:09 +00:00
|
|
|
case 'str': if(p.v) p.v = utf8read(p.v); break;
|
2014-01-28 16:38:02 +00:00
|
|
|
case 'inlineStr':
|
2014-01-29 06:00:09 +00:00
|
|
|
var is = d.match(/<is>(.*)<\/is>/);
|
|
|
|
is = is ? parse_si(is[1]) : {t:"",r:""};
|
|
|
|
p.t = 'str'; p.v = is.t;
|
2014-01-28 16:38:02 +00:00
|
|
|
break; // inline string
|
2014-02-15 05:08:18 +00:00
|
|
|
case 'b': if(typeof p.v !== 'boolean') p.v = parsexmlbool(p.v); break;
|
|
|
|
case 'd': /* TODO: date1904 logic */
|
2014-02-15 03:15:10 +00:00
|
|
|
var epoch = Date.parse(p.v);
|
|
|
|
p.v = (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000);
|
|
|
|
p.t = 'n';
|
|
|
|
break;
|
2014-01-28 16:38:02 +00:00
|
|
|
/* in case of error, stick value in .raw */
|
|
|
|
case 'e': p.raw = RBErr[p.v]; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* formatting */
|
|
|
|
var fmtid = 0;
|
|
|
|
if(cell.s && styles.CellXf) {
|
|
|
|
var cf = styles.CellXf[cell.s];
|
|
|
|
if(cf && cf.numFmtId) fmtid = cf.numFmtId;
|
|
|
|
}
|
2014-02-07 10:53:40 +00:00
|
|
|
try {
|
|
|
|
p.w = SSF.format(fmtid,p.v,_ssfopts);
|
|
|
|
if(opts.cellNF) p.z = SSF._table[fmtid];
|
2014-02-15 05:08:18 +00:00
|
|
|
} catch(e) { if(opts.WTF) throw e; }
|
2014-01-28 16:38:02 +00:00
|
|
|
s[cell.r] = p;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
if(!s["!ref"]) s["!ref"] = encode_range(refguess);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|