2014-06-29 18:29:45 +00:00
|
|
|
function parse_ws_xml_dim(ws, s) {
|
|
|
|
var d = safe_decode_range(s);
|
2014-07-28 13:22:32 +00:00
|
|
|
if(d.s.r<=d.e.r && d.s.c<=d.e.c && d.s.r>=0 && d.s.c>=0) ws["!ref"] = encode_range(d);
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
|
|
|
var mergecregex = /<mergeCell ref="[A-Z0-9:]+"\s*\/>/g;
|
|
|
|
var sheetdataregex = /<(?:\w+:)?sheetData>([^\u2603]*)<\/(?:\w+:)?sheetData>/;
|
|
|
|
var hlinkregex = /<hyperlink[^>]*\/>/g;
|
2014-07-28 13:22:32 +00:00
|
|
|
var dimregex = /"(\w*:\w*)"/;
|
|
|
|
var colregex = /<col[^>]*\/>/g;
|
2014-01-28 16:38:02 +00:00
|
|
|
/* 18.3 Worksheets */
|
2014-04-15 09:04:03 +00:00
|
|
|
function parse_ws_xml(data, opts, rels) {
|
2014-01-28 16:38:02 +00:00
|
|
|
if(!data) return data;
|
|
|
|
/* 18.3.1.99 worksheet CT_Worksheet */
|
2014-06-29 18:29:45 +00:00
|
|
|
var s = {};
|
2014-01-28 16:38:02 +00:00
|
|
|
|
|
|
|
/* 18.3.1.35 dimension CT_SheetDimension ? */
|
2014-06-29 18:29:45 +00:00
|
|
|
var ridx = data.indexOf("<dimension");
|
|
|
|
if(ridx > 0) {
|
2014-07-28 13:22:32 +00:00
|
|
|
var ref = data.substr(ridx,50).match(dimregex);
|
2014-06-29 18:29:45 +00:00
|
|
|
if(ref != null) parse_ws_xml_dim(s, ref[1]);
|
|
|
|
}
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2014-03-23 21:30:00 +00:00
|
|
|
/* 18.3.1.55 mergeCells CT_MergeCells */
|
|
|
|
var mergecells = [];
|
2014-06-29 18:29:45 +00:00
|
|
|
if(data.indexOf("</mergeCells>")!==-1) {
|
|
|
|
var merges = data.match(mergecregex);
|
|
|
|
for(ridx = 0; ridx != merges.length; ++ridx)
|
|
|
|
mergecells[ridx] = safe_decode_range(merges[ridx].substr(merges[ridx].indexOf("\"")+1));
|
2014-03-23 21:30:00 +00:00
|
|
|
}
|
|
|
|
|
2014-06-02 05:19:07 +00:00
|
|
|
/* 18.3.1.17 cols CT_Cols */
|
|
|
|
var columns = [];
|
2014-06-29 18:29:45 +00:00
|
|
|
if(opts.cellStyles && data.indexOf("</cols>")!==-1) {
|
2014-06-02 05:19:07 +00:00
|
|
|
/* 18.3.1.13 col CT_Col */
|
2014-07-28 13:22:32 +00:00
|
|
|
var cols = data.match(colregex);
|
2014-06-05 07:06:20 +00:00
|
|
|
parse_ws_xml_cols(columns, cols);
|
2014-06-02 05:19:07 +00:00
|
|
|
}
|
|
|
|
|
2014-01-28 16:38:02 +00:00
|
|
|
var refguess = {s: {r:1000000, c:1000000}, e: {r:0, c:0} };
|
2014-03-23 21:30:00 +00:00
|
|
|
|
2014-01-28 16:38:02 +00:00
|
|
|
/* 18.3.1.80 sheetData CT_SheetData ? */
|
2014-06-29 18:29:45 +00:00
|
|
|
var mtch=data.match(sheetdataregex);
|
|
|
|
if(mtch) parse_ws_xml_data(mtch[1], s, opts, refguess);
|
2014-04-15 09:04:03 +00:00
|
|
|
|
|
|
|
/* 18.3.1.48 hyperlinks CT_Hyperlinks */
|
2014-06-29 18:29:45 +00:00
|
|
|
if(data.indexOf("</hyperlinks>")!==-1) parse_ws_xml_hlinks(s, data.match(hlinkregex), rels);
|
2014-04-15 09:04:03 +00:00
|
|
|
|
2014-03-29 22:53:15 +00:00
|
|
|
if(!s["!ref"] && refguess.e.c >= refguess.s.c && refguess.e.r >= refguess.s.r) s["!ref"] = encode_range(refguess);
|
2014-06-29 18:29:45 +00:00
|
|
|
if(opts.sheetRows > 0 && s["!ref"]) {
|
|
|
|
var tmpref = safe_decode_range(s["!ref"]);
|
2014-02-19 03:03:28 +00:00
|
|
|
if(opts.sheetRows < +tmpref.e.r) {
|
|
|
|
tmpref.e.r = opts.sheetRows - 1;
|
|
|
|
if(tmpref.e.r > refguess.e.r) tmpref.e.r = refguess.e.r;
|
|
|
|
if(tmpref.e.r < tmpref.s.r) tmpref.s.r = tmpref.e.r;
|
|
|
|
if(tmpref.e.c > refguess.e.c) tmpref.e.c = refguess.e.c;
|
|
|
|
if(tmpref.e.c < tmpref.s.c) tmpref.s.c = tmpref.e.c;
|
|
|
|
s["!fullref"] = s["!ref"];
|
|
|
|
s["!ref"] = encode_range(tmpref);
|
|
|
|
}
|
|
|
|
}
|
2014-03-23 21:30:00 +00:00
|
|
|
if(mergecells.length > 0) s["!merges"] = mergecells;
|
2014-06-02 05:19:07 +00:00
|
|
|
if(columns.length > 0) s["!cols"] = columns;
|
2014-01-28 16:38:02 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2014-08-26 17:40:04 +00:00
|
|
|
function write_ws_xml_merges(merges) {
|
|
|
|
if(merges.length == 0) return "";
|
|
|
|
var o = '<mergeCells count="' + merges.length + '">';
|
|
|
|
for(var i = 0; i != merges.length; ++i) o += '<mergeCell ref="' + encode_range(merges[i]) + '"/>';
|
|
|
|
return o + '</mergeCells>';
|
|
|
|
}
|
2014-06-02 05:19:07 +00:00
|
|
|
|
2015-12-05 02:23:19 +00:00
|
|
|
function write_ws_xml_pagesetup(setup) {
|
2015-12-05 02:53:47 +00:00
|
|
|
var pageSetup = writextag('pageSetup', null, {
|
|
|
|
scale: setup.scale || '100',
|
2015-12-05 02:23:19 +00:00
|
|
|
orientation: setup.orientation || 'portrait',
|
|
|
|
horizontalDpi : setup.horizontalDpi || '4294967292',
|
|
|
|
verticalDpi : setup.verticalDpi || '4294967292'
|
|
|
|
})
|
2015-12-05 02:53:47 +00:00
|
|
|
console.log(pageSetup);
|
|
|
|
return pageSetup;
|
2015-12-05 02:23:19 +00:00
|
|
|
}
|
|
|
|
|
2015-12-05 02:02:05 +00:00
|
|
|
//<pageSetup scale="90" orientation="portrait" horizontalDpi="4294967292" verticalDpi="4294967292"/>
|
|
|
|
//<rowBreaks count="1" manualBreakCount="1">
|
|
|
|
// <brk id="8" max="16383" man="1"/>
|
|
|
|
//</rowBreaks>
|
|
|
|
//<colBreaks count="1" manualBreakCount="1">
|
|
|
|
// <brk id="8" max="1048575" man="1"/>
|
|
|
|
//</colBreaks>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
function parse_ws_xml_hlinks(s, data, rels) {
|
|
|
|
for(var i = 0; i != data.length; ++i) {
|
|
|
|
var val = parsexmltag(data[i], true);
|
2014-06-05 07:06:20 +00:00
|
|
|
if(!val.ref) return;
|
2014-11-13 08:42:15 +00:00
|
|
|
var rel = rels ? rels['!id'][val.id] : null;
|
2014-06-05 07:06:20 +00:00
|
|
|
if(rel) {
|
|
|
|
val.Target = rel.Target;
|
|
|
|
if(val.location) val.Target += "#"+val.location;
|
|
|
|
val.Rel = rel;
|
2014-11-13 08:42:15 +00:00
|
|
|
} else {
|
|
|
|
val.Target = val.location;
|
|
|
|
rel = {Target: val.location, TargetMode: 'Internal'};
|
|
|
|
val.Rel = rel;
|
2014-06-05 07:06:20 +00:00
|
|
|
}
|
2014-06-29 18:29:45 +00:00
|
|
|
var rng = safe_decode_range(val.ref);
|
2014-06-05 07:06:20 +00:00
|
|
|
for(var R=rng.s.r;R<=rng.e.r;++R) for(var C=rng.s.c;C<=rng.e.c;++C) {
|
|
|
|
var addr = encode_cell({c:C,r:R});
|
2014-10-26 05:26:18 +00:00
|
|
|
if(!s[addr]) s[addr] = {t:"stub",v:undefined};
|
2014-06-05 07:06:20 +00:00
|
|
|
s[addr].l = val;
|
|
|
|
}
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-05 07:06:20 +00:00
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
function parse_ws_xml_cols(columns, cols) {
|
2014-06-05 07:06:20 +00:00
|
|
|
var seencol = false;
|
|
|
|
for(var coli = 0; coli != cols.length; ++coli) {
|
|
|
|
var coll = parsexmltag(cols[coli], true);
|
2014-06-29 18:29:45 +00:00
|
|
|
var colm=parseInt(coll.min, 10)-1, colM=parseInt(coll.max,10)-1;
|
2014-06-05 07:06:20 +00:00
|
|
|
delete coll.min; delete coll.max;
|
|
|
|
if(!seencol && coll.width) { seencol = true; find_mdw(+coll.width, coll); }
|
|
|
|
if(coll.width) {
|
|
|
|
coll.wpx = width2px(+coll.width);
|
|
|
|
coll.wch = px2char(coll.wpx);
|
|
|
|
coll.MDW = MDW;
|
|
|
|
}
|
|
|
|
while(colm <= colM) columns[colm++] = coll;
|
|
|
|
}
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-06-05 07:06:20 +00:00
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
function write_ws_xml_cols(ws, cols) {
|
2014-06-05 07:06:20 +00:00
|
|
|
var o = ["<cols>"], col, width;
|
|
|
|
for(var i = 0; i != cols.length; ++i) {
|
|
|
|
if(!(col = cols[i])) continue;
|
|
|
|
var p = {min:i+1,max:i+1};
|
|
|
|
/* wch (chars), wpx (pixels) */
|
|
|
|
width = -1;
|
|
|
|
if(col.wpx) width = px2char(col.wpx);
|
|
|
|
else if(col.wch) width = col.wch;
|
|
|
|
if(width > -1) { p.width = char2width(width); p.customWidth= 1; }
|
2014-06-29 18:29:45 +00:00
|
|
|
o[o.length] = (writextag('col', null, p));
|
2014-06-05 07:06:20 +00:00
|
|
|
}
|
2014-06-29 18:29:45 +00:00
|
|
|
o[o.length] = "</cols>";
|
2014-06-05 07:06:20 +00:00
|
|
|
return o.join("");
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-05-16 00:33:34 +00:00
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
function write_ws_xml_cell(cell, ref, ws, opts, idx, wb) {
|
2015-08-11 21:20:09 +00:00
|
|
|
if(cell.v === undefined && cell.s === undefined) return "";
|
2014-06-29 18:29:45 +00:00
|
|
|
var vv = "";
|
2014-10-26 05:26:18 +00:00
|
|
|
var oldt = cell.t, oldv = cell.v;
|
2014-06-29 18:29:45 +00:00
|
|
|
switch(cell.t) {
|
|
|
|
case 'b': vv = cell.v ? "1" : "0"; break;
|
2014-10-26 05:26:18 +00:00
|
|
|
case 'n': vv = ''+cell.v; break;
|
|
|
|
case 'e': vv = BErr[cell.v]; break;
|
|
|
|
case 'd':
|
|
|
|
if(opts.cellDates) vv = new Date(cell.v).toISOString();
|
|
|
|
else {
|
|
|
|
cell.t = 'n';
|
|
|
|
vv = ''+(cell.v = datenum(cell.v));
|
|
|
|
if(typeof cell.z === 'undefined') cell.z = SSF._table[14];
|
|
|
|
}
|
|
|
|
break;
|
2014-06-29 18:29:45 +00:00
|
|
|
default: vv = cell.v; break;
|
|
|
|
}
|
|
|
|
var v = writetag('v', escapexml(vv)), o = {r:ref};
|
2014-05-16 00:33:34 +00:00
|
|
|
/* TODO: cell style */
|
2014-06-29 18:29:45 +00:00
|
|
|
var os = get_cell_style(opts.cellXfs, cell, opts);
|
|
|
|
if(os !== 0) o.s = os;
|
2014-05-16 00:33:34 +00:00
|
|
|
switch(cell.t) {
|
2014-07-28 13:22:32 +00:00
|
|
|
case 'n': break;
|
2014-10-26 05:26:18 +00:00
|
|
|
case 'd': o.t = "d"; break;
|
2014-07-28 13:22:32 +00:00
|
|
|
case 'b': o.t = "b"; break;
|
|
|
|
case 'e': o.t = "e"; break;
|
|
|
|
default:
|
2014-05-16 00:33:34 +00:00
|
|
|
if(opts.bookSST) {
|
2014-06-29 18:29:45 +00:00
|
|
|
v = writetag('v', ''+get_sst_id(opts.Strings, cell.v));
|
|
|
|
o.t = "s"; break;
|
2014-06-05 07:06:20 +00:00
|
|
|
}
|
2014-06-29 18:29:45 +00:00
|
|
|
o.t = "str"; break;
|
2014-05-16 00:33:34 +00:00
|
|
|
}
|
2014-10-26 05:26:18 +00:00
|
|
|
if(cell.t != oldt) { cell.t = oldt; cell.v = oldv; }
|
2014-06-29 18:29:45 +00:00
|
|
|
return writextag('c', v, o);
|
|
|
|
}
|
|
|
|
|
|
|
|
var parse_ws_xml_data = (function parse_ws_xml_data_factory() {
|
2014-10-10 02:22:38 +00:00
|
|
|
var cellregex = /<(?:\w+:)?c[ >]/, rowregex = /<\/(?:\w+:)?row>/;
|
2014-06-29 18:29:45 +00:00
|
|
|
var rregex = /r=["']([^"']*)["']/, isregex = /<is>([\S\s]*?)<\/is>/;
|
|
|
|
var match_v = matchtag("v"), match_f = matchtag("f");
|
|
|
|
|
|
|
|
return function parse_ws_xml_data(sdata, s, opts, guess) {
|
|
|
|
var ri = 0, x = "", cells = [], cref = [], idx = 0, i=0, cc=0, d="", p;
|
2014-10-10 02:22:38 +00:00
|
|
|
var tag, tagr = 0, tagc = 0;
|
2014-06-29 18:29:45 +00:00
|
|
|
var sstr;
|
|
|
|
var fmtid = 0, fillid = 0, do_format = Array.isArray(styles.CellXf), cf;
|
2014-07-28 13:22:32 +00:00
|
|
|
for(var marr = sdata.split(rowregex), mt = 0, marrlen = marr.length; mt != marrlen; ++mt) {
|
2014-06-29 18:29:45 +00:00
|
|
|
x = marr[mt].trim();
|
2014-07-28 13:22:32 +00:00
|
|
|
var xlen = x.length;
|
|
|
|
if(xlen === 0) continue;
|
2014-05-16 00:33:34 +00:00
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
/* 18.3.1.73 row CT_Row */
|
2014-07-28 13:22:32 +00:00
|
|
|
for(ri = 0; ri < xlen; ++ri) if(x.charCodeAt(ri) === 62) break; ++ri;
|
2014-06-29 18:29:45 +00:00
|
|
|
tag = parsexmltag(x.substr(0,ri), true);
|
2014-10-10 02:22:38 +00:00
|
|
|
/* SpreadSheetGear uses implicit r/c */
|
|
|
|
tagr = typeof tag.r !== 'undefined' ? parseInt(tag.r, 10) : tagr+1; tagc = -1;
|
2014-07-28 13:22:32 +00:00
|
|
|
if(opts.sheetRows && opts.sheetRows < tagr) continue;
|
|
|
|
if(guess.s.r > tagr - 1) guess.s.r = tagr - 1;
|
|
|
|
if(guess.e.r < tagr - 1) guess.e.r = tagr - 1;
|
2014-06-29 18:29:45 +00:00
|
|
|
|
|
|
|
/* 18.3.1.4 c CT_Cell */
|
|
|
|
cells = x.substr(ri).split(cellregex);
|
2014-10-10 02:22:38 +00:00
|
|
|
for(ri = typeof tag.r === 'undefined' ? 0 : 1; ri != cells.length; ++ri) {
|
2014-06-29 18:29:45 +00:00
|
|
|
x = cells[ri].trim();
|
|
|
|
if(x.length === 0) continue;
|
|
|
|
cref = x.match(rregex); idx = ri; i=0; cc=0;
|
2014-10-10 02:22:38 +00:00
|
|
|
x = "<c " + (x.substr(0,1)=="<"?">":"") + x;
|
2014-06-29 18:29:45 +00:00
|
|
|
if(cref !== null && cref.length === 2) {
|
|
|
|
idx = 0; d=cref[1];
|
|
|
|
for(i=0; i != d.length; ++i) {
|
|
|
|
if((cc=d.charCodeAt(i)-64) < 1 || cc > 26) break;
|
|
|
|
idx = 26*idx + cc;
|
|
|
|
}
|
|
|
|
--idx;
|
2014-10-10 02:22:38 +00:00
|
|
|
tagc = idx;
|
|
|
|
} else ++tagc;
|
2014-06-29 18:29:45 +00:00
|
|
|
for(i = 0; i != x.length; ++i) if(x.charCodeAt(i) === 62) break; ++i;
|
|
|
|
tag = parsexmltag(x.substr(0,i), true);
|
2014-10-10 02:22:38 +00:00
|
|
|
if(!tag.r) tag.r = utils.encode_cell({r:tagr-1, c:tagc});
|
2014-06-29 18:29:45 +00:00
|
|
|
d = x.substr(i);
|
|
|
|
p = {t:""};
|
|
|
|
|
2014-08-26 17:40:04 +00:00
|
|
|
if((cref=d.match(match_v))!== null && cref[1] !== '') p.v=unescapexml(cref[1]);
|
2014-06-29 18:29:45 +00:00
|
|
|
if(opts.cellFormula && (cref=d.match(match_f))!== null) p.f=unescapexml(cref[1]);
|
|
|
|
|
|
|
|
/* SCHEMA IS ACTUALLY INCORRECT HERE. IF A CELL HAS NO T, EMIT "" */
|
2015-08-11 21:20:09 +00:00
|
|
|
if(tag.t === undefined && tag.s === undefined && p.v === undefined) {
|
2014-06-29 18:29:45 +00:00
|
|
|
if(!opts.sheetStubs) continue;
|
2014-10-26 05:26:18 +00:00
|
|
|
p.t = "stub";
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
|
|
|
else p.t = tag.t || "n";
|
|
|
|
if(guess.s.c > idx) guess.s.c = idx;
|
|
|
|
if(guess.e.c < idx) guess.e.c = idx;
|
|
|
|
/* 18.18.11 t ST_CellType */
|
|
|
|
switch(p.t) {
|
2015-08-11 21:20:09 +00:00
|
|
|
case 'n':
|
|
|
|
p.v = parseFloat(p.v);
|
|
|
|
if(isNaN(p.v)) p.v = "" // we don't want NaN if p.v is null
|
|
|
|
break;
|
2014-06-29 18:29:45 +00:00
|
|
|
case 's':
|
|
|
|
sstr = strs[parseInt(p.v, 10)];
|
|
|
|
p.v = sstr.t;
|
|
|
|
p.r = sstr.r;
|
|
|
|
if(opts.cellHTML) p.h = sstr.h;
|
|
|
|
break;
|
2014-10-26 05:26:18 +00:00
|
|
|
case 'str':
|
|
|
|
p.t = "s";
|
|
|
|
p.v = (p.v!=null) ? utf8read(p.v) : '';
|
|
|
|
if(opts.cellHTML) p.h = p.v;
|
|
|
|
break;
|
2014-06-29 18:29:45 +00:00
|
|
|
case 'inlineStr':
|
|
|
|
cref = d.match(isregex);
|
2014-10-26 05:26:18 +00:00
|
|
|
p.t = 's';
|
2014-06-29 18:29:45 +00:00
|
|
|
if(cref !== null) { sstr = parse_si(cref[1]); p.v = sstr.t; } else p.v = "";
|
|
|
|
break; // inline string
|
|
|
|
case 'b': p.v = parsexmlbool(p.v); break;
|
|
|
|
case 'd':
|
2014-10-26 05:26:18 +00:00
|
|
|
if(!opts.cellDates) { p.v = datenum(p.v); p.t = 'n'; }
|
2014-06-29 18:29:45 +00:00
|
|
|
break;
|
2014-10-26 05:26:18 +00:00
|
|
|
/* error string in .v, number in .v */
|
|
|
|
case 'e': p.w = p.v; p.v = RBErr[p.v]; break;
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2015-03-28 16:32:46 +00:00
|
|
|
/* formatting */
|
|
|
|
fmtid = fillid = 0;
|
|
|
|
if(do_format && tag.s !== undefined) {
|
|
|
|
cf = styles.CellXf[tag.s];
|
2015-03-29 19:21:11 +00:00
|
|
|
if (opts.cellStyles) {
|
|
|
|
p.s = get_cell_style_csf(cf)
|
|
|
|
}
|
2015-03-28 16:32:46 +00:00
|
|
|
if(cf != null) {
|
|
|
|
if(cf.numFmtId != null) fmtid = cf.numFmtId;
|
|
|
|
if(opts.cellStyles && cf.fillId != null) fillid = cf.fillId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
safe_format(p, fmtid, fillid, opts);
|
|
|
|
s[tag.r] = p;
|
|
|
|
}
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
|
|
|
}; })();
|
|
|
|
|
|
|
|
function write_ws_xml_data(ws, opts, idx, wb) {
|
2014-07-28 13:22:32 +00:00
|
|
|
var o = [], r = [], range = safe_decode_range(ws['!ref']), cell, ref, rr = "", cols = [], R, C;
|
|
|
|
for(C = range.s.c; C <= range.e.c; ++C) cols[C] = encode_col(C);
|
|
|
|
for(R = range.s.r; R <= range.e.r; ++R) {
|
2014-05-16 00:33:34 +00:00
|
|
|
r = [];
|
2014-06-29 18:29:45 +00:00
|
|
|
rr = encode_row(R);
|
2014-07-28 13:22:32 +00:00
|
|
|
for(C = range.s.c; C <= range.e.c; ++C) {
|
2014-06-29 18:29:45 +00:00
|
|
|
ref = cols[C] + rr;
|
2014-07-28 13:22:32 +00:00
|
|
|
if(ws[ref] === undefined) continue;
|
|
|
|
if((cell = write_ws_xml_cell(ws[ref], ref, ws, opts, idx, wb)) != null) r.push(cell);
|
2014-05-16 00:33:34 +00:00
|
|
|
}
|
2014-07-28 13:22:32 +00:00
|
|
|
if(r.length > 0) o[o.length] = (writextag('row', r.join(""), {r:rr}));
|
2014-05-16 00:33:34 +00:00
|
|
|
}
|
|
|
|
return o.join("");
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-05-16 00:33:34 +00:00
|
|
|
|
2014-06-05 07:06:20 +00:00
|
|
|
var WS_XML_ROOT = writextag('worksheet', null, {
|
|
|
|
'xmlns': XMLNS.main[0],
|
|
|
|
'xmlns:r': XMLNS.r
|
|
|
|
});
|
2014-06-02 05:19:07 +00:00
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
function write_ws_xml(idx, opts, wb) {
|
|
|
|
var o = [XML_HEADER, WS_XML_ROOT];
|
2014-07-28 13:22:32 +00:00
|
|
|
var s = wb.SheetNames[idx], sidx = 0, rdata = "";
|
|
|
|
var ws = wb.Sheets[s];
|
|
|
|
if(ws === undefined) ws = {};
|
|
|
|
var ref = ws['!ref']; if(ref === undefined) ref = 'A1';
|
|
|
|
o[o.length] = (writextag('dimension', null, {'ref': ref}));
|
|
|
|
|
2015-12-04 14:53:43 +00:00
|
|
|
var sheetView = writextag('sheetView', null, {
|
|
|
|
showGridLines: opts.showGridLines == false ? '0' : '1',
|
2016-04-06 03:17:01 +00:00
|
|
|
tabSelected: opts.tabSelected === undefined ? '0' : opts.tabSelected, // see issue #26, need to set WorkbookViews if this is set
|
2015-12-04 14:53:43 +00:00
|
|
|
workbookViewId: opts.workbookViewId === undefined ? '0' : opts.workbookViewId
|
|
|
|
});
|
|
|
|
o[o.length] = writextag('sheetViews', sheetView);
|
|
|
|
|
2014-07-28 13:22:32 +00:00
|
|
|
if(ws['!cols'] !== undefined && ws['!cols'].length > 0) o[o.length] = (write_ws_xml_cols(ws, ws['!cols']));
|
|
|
|
o[sidx = o.length] = '<sheetData/>';
|
|
|
|
if(ws['!ref'] !== undefined) {
|
|
|
|
rdata = write_ws_xml_data(ws, opts, idx, wb);
|
|
|
|
if(rdata.length > 0) o[o.length] = (rdata);
|
|
|
|
}
|
2014-06-29 18:29:45 +00:00
|
|
|
if(o.length>sidx+1) { o[o.length] = ('</sheetData>'); o[sidx]=o[sidx].replace("/>",">"); }
|
2014-05-16 00:33:34 +00:00
|
|
|
|
2014-08-26 17:40:04 +00:00
|
|
|
if(ws['!merges'] !== undefined && ws['!merges'].length > 0) o[o.length] = (write_ws_xml_merges(ws['!merges']));
|
|
|
|
|
2015-12-05 02:53:47 +00:00
|
|
|
if (ws['!pageSetup'] !== undefined) o[o.length] = write_ws_xml_pagesetup(ws['!pageSetup'])
|
2015-12-05 02:02:05 +00:00
|
|
|
if (ws['!rowBreaks'] !== undefined) o[o.length] = write_ws_xml_row_breaks(ws['!rowBreaks'])
|
|
|
|
if (ws['!colBreaks'] !== undefined) o[o.length] = write_ws_xml_col_breaks(ws['!colBreaks'])
|
2015-12-05 02:53:47 +00:00
|
|
|
|
2015-12-05 02:02:05 +00:00
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
if(o.length>2) { o[o.length] = ('</worksheet>'); o[1]=o[1].replace("/>",">"); }
|
2014-05-16 00:33:34 +00:00
|
|
|
return o.join("");
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2015-12-05 02:02:05 +00:00
|
|
|
|
|
|
|
function write_ws_xml_row_breaks(breaks) {
|
|
|
|
console.log("Writing breaks")
|
|
|
|
var brk = [];
|
|
|
|
for (var i=0; i<breaks.length; i++) {
|
|
|
|
var thisBreak = ''+ (breaks[i]);
|
|
|
|
var nextBreak = '' + (breaks[i+1] || '16383');
|
|
|
|
brk.push(writextag('brk', null, {id: thisBreak, max: nextBreak, man: '1'}))
|
|
|
|
}
|
|
|
|
return writextag('rowBreaks', brk.join(' '), {count: brk.length, manualBreakCount: brk.length})
|
|
|
|
}
|
|
|
|
function write_ws_xml_col_breaks(breaks) {
|
|
|
|
console.log("Writing breaks");
|
|
|
|
var brk = [];
|
|
|
|
for (var i=0; i<breaks.length; i++) {
|
|
|
|
var thisBreak = ''+ (breaks[i]);
|
2015-12-05 02:53:47 +00:00
|
|
|
var nextBreak = '' + (breaks[i+1] || '1048575');
|
2015-12-05 02:02:05 +00:00
|
|
|
brk.push(writextag('brk', null, {id: thisBreak, max: nextBreak, man: '1'}))
|
|
|
|
}
|
|
|
|
return writextag('colBreaks', brk.join(' '), {count: brk.length, manualBreakCount: brk.length})
|
|
|
|
}
|