2017-12-30 05:40:35 +00:00
|
|
|
function parse_ws_xml_dim(ws/*:Worksheet*/, s/*:string*/) {
|
2014-06-29 18:29:45 +00:00
|
|
|
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
|
|
|
}
|
2017-03-20 21:42:12 +00:00
|
|
|
var mergecregex = /<(?:\w:)?mergeCell ref="[A-Z0-9:]+"\s*[\/]?>/g;
|
2019-08-14 20:11:16 +00:00
|
|
|
var sheetdataregex = /<(?:\w+:)?sheetData[^>]*>([\s\S]*)<\/(?:\w+:)?sheetData>/;
|
2017-04-09 04:03:19 +00:00
|
|
|
var hlinkregex = /<(?:\w:)?hyperlink [^>]*>/mg;
|
2014-07-28 13:22:32 +00:00
|
|
|
var dimregex = /"(\w*:\w*)"/;
|
2019-04-01 14:25:15 +00:00
|
|
|
var colregex = /<(?:\w:)?col\b[^>]*[\/]?>/g;
|
2017-06-24 06:51:37 +00:00
|
|
|
var afregex = /<(?:\w:)?autoFilter[^>]*([\/]|>([\s\S]*)<\/(?:\w:)?autoFilter)>/g;
|
2017-04-13 01:29:38 +00:00
|
|
|
var marginregex= /<(?:\w:)?pageMargins[^>]*\/>/g;
|
2019-04-30 07:30:54 +00:00
|
|
|
var sheetprregex = /<(?:\w:)?sheetPr\b(?:[^>a-z][^>]*)?\/>/;
|
2021-09-22 06:45:08 +00:00
|
|
|
var sheetprregex2= /<(?:\w:)?sheetPr[^>]*(?:[\/]|>([\s\S]*)<\/(?:\w:)?sheetPr)>/;
|
2017-12-30 05:40:35 +00:00
|
|
|
var svsregex = /<(?:\w:)?sheetViews[^>]*(?:[\/]|>([\s\S]*)<\/(?:\w:)?sheetViews)>/;
|
2019-11-01 03:09:14 +00:00
|
|
|
|
2014-01-28 16:38:02 +00:00
|
|
|
/* 18.3 Worksheets */
|
2017-12-30 05:40:35 +00:00
|
|
|
function parse_ws_xml(data/*:?string*/, opts, idx/*:number*/, rels, wb/*:WBWBProps*/, themes, styles)/*:Worksheet*/ {
|
2014-01-28 16:38:02 +00:00
|
|
|
if(!data) return data;
|
2019-11-01 03:09:14 +00:00
|
|
|
if(!rels) rels = {'!id':{}};
|
2017-04-09 04:03:19 +00:00
|
|
|
if(DENSE != null && opts.dense == null) opts.dense = DENSE;
|
2017-04-10 05:10:54 +00:00
|
|
|
|
2014-01-28 16:38:02 +00:00
|
|
|
/* 18.3.1.99 worksheet CT_Worksheet */
|
2022-10-24 01:05:59 +00:00
|
|
|
var s = ({}/*:any*/); if(opts.dense) s["!data"] = [];
|
2017-04-10 05:10:54 +00:00
|
|
|
var refguess/*:Range*/ = ({s: {r:2000000, c:2000000}, e: {r:0, c:0} }/*:any*/);
|
|
|
|
|
|
|
|
var data1 = "", data2 = "";
|
2017-06-10 01:47:42 +00:00
|
|
|
var mtch/*:?any*/ = data.match(sheetdataregex);
|
2017-04-10 05:10:54 +00:00
|
|
|
if(mtch) {
|
2018-01-11 08:01:25 +00:00
|
|
|
data1 = data.slice(0, mtch.index);
|
|
|
|
data2 = data.slice(mtch.index + mtch[0].length);
|
2017-04-10 05:10:54 +00:00
|
|
|
} else data1 = data2 = data;
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2017-11-20 01:51:14 +00:00
|
|
|
/* 18.3.1.82 sheetPr CT_SheetPr */
|
|
|
|
var sheetPr = data1.match(sheetprregex);
|
|
|
|
if(sheetPr) parse_ws_xml_sheetpr(sheetPr[0], s, wb, idx);
|
2021-09-22 06:45:08 +00:00
|
|
|
else if((sheetPr = data1.match(sheetprregex2))) parse_ws_xml_sheetpr2(sheetPr[0], sheetPr[1]||"", s, wb, idx, styles, themes);
|
2017-11-20 01:51:14 +00:00
|
|
|
|
2017-12-30 05:40:35 +00:00
|
|
|
/* 18.3.1.35 dimension CT_SheetDimension */
|
2017-04-10 05:10:54 +00:00
|
|
|
var ridx = (data1.match(/<(?:\w*:)?dimension/)||{index:-1}).index;
|
2014-06-29 18:29:45 +00:00
|
|
|
if(ridx > 0) {
|
2018-01-11 08:01:25 +00:00
|
|
|
var ref = data1.slice(ridx,ridx+50).match(dimregex);
|
2022-11-17 09:35:34 +00:00
|
|
|
if(ref && !(opts && opts.nodim)) parse_ws_xml_dim(s, ref[1]);
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2017-12-30 05:40:35 +00:00
|
|
|
/* 18.3.1.88 sheetViews CT_SheetViews */
|
|
|
|
var svs = data1.match(svsregex);
|
|
|
|
if(svs && svs[1]) parse_ws_xml_sheetviews(svs[1], wb);
|
|
|
|
|
2014-06-02 05:19:07 +00:00
|
|
|
/* 18.3.1.17 cols CT_Cols */
|
2017-12-30 05:40:35 +00:00
|
|
|
var columns/*:Array<ColInfo>*/ = [];
|
2017-02-10 19:23:01 +00:00
|
|
|
if(opts.cellStyles) {
|
2014-06-02 05:19:07 +00:00
|
|
|
/* 18.3.1.13 col CT_Col */
|
2017-04-10 05:10:54 +00:00
|
|
|
var cols = data1.match(colregex);
|
2017-02-10 19:23:01 +00:00
|
|
|
if(cols) parse_ws_xml_cols(columns, cols);
|
2014-06-02 05:19:07 +00:00
|
|
|
}
|
|
|
|
|
2014-01-28 16:38:02 +00:00
|
|
|
/* 18.3.1.80 sheetData CT_SheetData ? */
|
2017-03-18 23:25:50 +00:00
|
|
|
if(mtch) parse_ws_xml_data(mtch[1], s, opts, refguess, themes, styles);
|
2014-04-15 09:04:03 +00:00
|
|
|
|
2017-04-10 05:10:54 +00:00
|
|
|
/* 18.3.1.2 autoFilter CT_AutoFilter */
|
|
|
|
var afilter = data2.match(afregex);
|
|
|
|
if(afilter) s['!autofilter'] = parse_ws_xml_autofilter(afilter[0]);
|
|
|
|
|
|
|
|
/* 18.3.1.55 mergeCells CT_MergeCells */
|
2017-12-30 05:40:35 +00:00
|
|
|
var merges/*:Array<Range>*/ = [];
|
|
|
|
var _merge = data2.match(mergecregex);
|
|
|
|
if(_merge) for(ridx = 0; ridx != _merge.length; ++ridx)
|
2018-01-11 08:01:25 +00:00
|
|
|
merges[ridx] = safe_decode_range(_merge[ridx].slice(_merge[ridx].indexOf("\"")+1));
|
2017-04-10 05:10:54 +00:00
|
|
|
|
2014-04-15 09:04:03 +00:00
|
|
|
/* 18.3.1.48 hyperlinks CT_Hyperlinks */
|
2017-04-10 05:10:54 +00:00
|
|
|
var hlink = data2.match(hlinkregex);
|
2017-02-10 19:23:01 +00:00
|
|
|
if(hlink) parse_ws_xml_hlinks(s, hlink, rels);
|
2014-04-15 09:04:03 +00:00
|
|
|
|
2017-04-13 01:29:38 +00:00
|
|
|
/* 18.3.1.62 pageMargins CT_PageMargins */
|
|
|
|
var margins = data2.match(marginregex);
|
|
|
|
if(margins) s['!margins'] = parse_ws_xml_margins(parsexmltag(margins[0]));
|
|
|
|
|
2023-06-13 04:49:18 +00:00
|
|
|
/* legacyDrawing */
|
|
|
|
if((m = data2.match(/legacyDrawing r:id="(.*?)"/))) s['!legrel'] = m[1];
|
|
|
|
|
2022-11-17 09:35:34 +00:00
|
|
|
if(opts && opts.nodim) refguess.s.c = refguess.s.r = 0;
|
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"]);
|
2018-04-06 06:39:48 +00:00
|
|
|
if(opts.sheetRows <= +tmpref.e.r) {
|
2014-02-19 03:03:28 +00:00
|
|
|
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-06-02 05:19:07 +00:00
|
|
|
if(columns.length > 0) s["!cols"] = columns;
|
2017-12-30 05:40:35 +00:00
|
|
|
if(merges.length > 0) s["!merges"] = merges;
|
2023-06-13 04:49:18 +00:00
|
|
|
if(rels['!id'][s['!legrel']]) s['!legdrawel'] = rels['!id'][s['!legrel']];
|
2014-01-28 16:38:02 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2017-12-30 05:40:35 +00:00
|
|
|
function write_ws_xml_merges(merges/*:Array<Range>*/)/*:string*/ {
|
2017-10-17 00:14:32 +00:00
|
|
|
if(merges.length === 0) return "";
|
2014-08-26 17:40:04 +00:00
|
|
|
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
|
|
|
|
2017-11-20 01:51:14 +00:00
|
|
|
/* 18.3.1.82-3 sheetPr CT_ChartsheetPr / CT_SheetPr */
|
|
|
|
function parse_ws_xml_sheetpr(sheetPr/*:string*/, s, wb/*:WBWBProps*/, idx/*:number*/) {
|
|
|
|
var data = parsexmltag(sheetPr);
|
|
|
|
if(!wb.Sheets[idx]) wb.Sheets[idx] = {};
|
2020-11-20 07:05:27 +00:00
|
|
|
if(data.codeName) wb.Sheets[idx].CodeName = unescapexml(utf8read(data.codeName));
|
2017-11-20 01:51:14 +00:00
|
|
|
}
|
2022-03-16 03:18:09 +00:00
|
|
|
function parse_ws_xml_sheetpr2(sheetPr/*:string*/, body/*:string*/, s, wb/*:WBWBProps*/, idx/*:number*/) {
|
2021-09-22 06:45:08 +00:00
|
|
|
parse_ws_xml_sheetpr(sheetPr.slice(0, sheetPr.indexOf(">")), s, wb, idx);
|
|
|
|
}
|
2019-11-15 01:46:49 +00:00
|
|
|
function write_ws_xml_sheetpr(ws, wb, idx, opts, o) {
|
|
|
|
var needed = false;
|
|
|
|
var props = {}, payload = null;
|
|
|
|
if(opts.bookType !== 'xlsx' && wb.vbaraw) {
|
|
|
|
var cname = wb.SheetNames[idx];
|
|
|
|
try { if(wb.Workbook) cname = wb.Workbook.Sheets[idx].CodeName || cname; } catch(e) {}
|
|
|
|
needed = true;
|
2020-11-20 07:05:27 +00:00
|
|
|
props.codeName = utf8write(escapexml(cname));
|
2019-11-15 01:46:49 +00:00
|
|
|
}
|
|
|
|
|
2020-11-02 21:45:11 +00:00
|
|
|
if(ws && ws["!outline"]) {
|
|
|
|
var outlineprops = {summaryBelow:1, summaryRight:1};
|
|
|
|
if(ws["!outline"].above) outlineprops.summaryBelow = 0;
|
|
|
|
if(ws["!outline"].left) outlineprops.summaryRight = 0;
|
|
|
|
payload = (payload||"") + writextag('outlinePr', null, outlineprops);
|
|
|
|
}
|
|
|
|
|
2019-11-15 01:46:49 +00:00
|
|
|
if(!needed && !payload) return;
|
|
|
|
o[o.length] = (writextag('sheetPr', payload, props));
|
|
|
|
}
|
2017-11-20 01:51:14 +00:00
|
|
|
|
|
|
|
/* 18.3.1.85 sheetProtection CT_SheetProtection */
|
2019-11-01 03:09:14 +00:00
|
|
|
var sheetprot_deffalse = ["objects", "scenarios", "selectLockedCells", "selectUnlockedCells"];
|
|
|
|
var sheetprot_deftrue = [
|
|
|
|
"formatColumns", "formatRows", "formatCells",
|
|
|
|
"insertColumns", "insertRows", "insertHyperlinks",
|
|
|
|
"deleteColumns", "deleteRows",
|
|
|
|
"sort", "autoFilter", "pivotTables"
|
|
|
|
];
|
2017-04-04 18:41:11 +00:00
|
|
|
function write_ws_xml_protection(sp)/*:string*/ {
|
2020-10-06 21:13:46 +00:00
|
|
|
// algorithmName, hashValue, saltValue, spinCount
|
2017-04-04 18:41:11 +00:00
|
|
|
var o = ({sheet:1}/*:any*/);
|
2019-11-01 03:09:14 +00:00
|
|
|
sheetprot_deffalse.forEach(function(n) { if(sp[n] != null && sp[n]) o[n] = "1"; });
|
|
|
|
sheetprot_deftrue.forEach(function(n) { if(sp[n] != null && !sp[n]) o[n] = "0"; });
|
2017-04-04 18:41:11 +00:00
|
|
|
/* TODO: algorithm */
|
|
|
|
if(sp.password) o.password = crypto_CreatePasswordVerifier_Method1(sp.password).toString(16).toUpperCase();
|
|
|
|
return writextag('sheetProtection', null, o);
|
|
|
|
}
|
|
|
|
|
2017-03-28 22:03:03 +00:00
|
|
|
function parse_ws_xml_hlinks(s, data/*:Array<string>*/, rels) {
|
2022-10-24 01:05:59 +00:00
|
|
|
var dense = s["!data"] != null;
|
2014-06-29 18:29:45 +00:00
|
|
|
for(var i = 0; i != data.length; ++i) {
|
2017-06-13 02:26:29 +00:00
|
|
|
var val = parsexmltag(utf8read(data[i]), true);
|
2014-06-05 07:06:20 +00:00
|
|
|
if(!val.ref) return;
|
2017-12-15 01:18:40 +00:00
|
|
|
var rel = ((rels || {})['!id']||[])[val.id];
|
2014-06-05 07:06:20 +00:00
|
|
|
if(rel) {
|
|
|
|
val.Target = rel.Target;
|
2021-09-30 07:28:03 +00:00
|
|
|
if(val.location) val.Target += "#"+unescapexml(val.location);
|
2014-11-13 08:42:15 +00:00
|
|
|
} else {
|
2021-09-30 07:28:03 +00:00
|
|
|
val.Target = "#" + unescapexml(val.location);
|
2017-12-15 01:18:40 +00:00
|
|
|
rel = {Target: val.Target, TargetMode: 'Internal'};
|
2014-06-05 07:06:20 +00:00
|
|
|
}
|
2017-12-15 01:18:40 +00:00
|
|
|
val.Rel = rel;
|
2017-03-28 22:03:03 +00:00
|
|
|
if(val.tooltip) { val.Tooltip = val.tooltip; delete val.tooltip; }
|
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) {
|
2022-10-24 01:05:59 +00:00
|
|
|
var addr = encode_col(C) + encode_row(R);
|
2017-04-08 06:55:35 +00:00
|
|
|
if(dense) {
|
2022-10-24 01:05:59 +00:00
|
|
|
if(!s["!data"][R]) s["!data"][R] = [];
|
|
|
|
if(!s["!data"][R][C]) s["!data"][R][C] = {t:"z",v:undefined};
|
|
|
|
s["!data"][R][C].l = val;
|
2017-04-08 06:55:35 +00:00
|
|
|
} else {
|
|
|
|
if(!s[addr]) s[addr] = {t:"z",v:undefined};
|
|
|
|
s[addr].l = val;
|
|
|
|
}
|
2014-06-05 07:06:20 +00:00
|
|
|
}
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-05 07:06:20 +00:00
|
|
|
|
2017-04-13 01:29:38 +00:00
|
|
|
function parse_ws_xml_margins(margin) {
|
|
|
|
var o = {};
|
|
|
|
["left", "right", "top", "bottom", "header", "footer"].forEach(function(k) {
|
|
|
|
if(margin[k]) o[k] = parseFloat(margin[k]);
|
|
|
|
});
|
|
|
|
return o;
|
|
|
|
}
|
2017-12-30 05:40:35 +00:00
|
|
|
function write_ws_xml_margins(margin)/*:string*/ {
|
2017-04-17 02:28:38 +00:00
|
|
|
default_margins(margin);
|
|
|
|
return writextag('pageMargins', null, margin);
|
|
|
|
}
|
2017-04-13 01:29:38 +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);
|
2017-04-28 07:28:03 +00:00
|
|
|
if(coll.hidden) coll.hidden = parsexmlbool(coll.hidden);
|
2014-06-29 18:29:45 +00:00
|
|
|
var colm=parseInt(coll.min, 10)-1, colM=parseInt(coll.max,10)-1;
|
2021-09-22 06:45:08 +00:00
|
|
|
if(coll.outlineLevel) coll.level = (+coll.outlineLevel || 0);
|
2017-03-20 09:02:25 +00:00
|
|
|
delete coll.min; delete coll.max; coll.width = +coll.width;
|
|
|
|
if(!seencol && coll.width) { seencol = true; find_mdw_colw(coll.width); }
|
|
|
|
process_col(coll);
|
|
|
|
while(colm <= colM) columns[colm++] = dup(coll);
|
2014-06-05 07:06:20 +00:00
|
|
|
}
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2017-02-10 19:23:01 +00:00
|
|
|
function write_ws_xml_cols(ws, cols)/*:string*/ {
|
2018-01-23 09:07:51 +00:00
|
|
|
var o = ["<cols>"], col;
|
2014-06-05 07:06:20 +00:00
|
|
|
for(var i = 0; i != cols.length; ++i) {
|
|
|
|
if(!(col = cols[i])) continue;
|
2017-03-28 22:03:03 +00:00
|
|
|
o[o.length] = (writextag('col', null, col_obj_w(i, col)));
|
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
|
|
|
|
2017-12-30 05:40:35 +00:00
|
|
|
function parse_ws_xml_autofilter(data/*:string*/) {
|
2017-04-10 05:10:54 +00:00
|
|
|
var o = { ref: (data.match(/ref="([^"]*)"/)||[])[1]};
|
|
|
|
return o;
|
|
|
|
}
|
2018-11-13 20:25:51 +00:00
|
|
|
function write_ws_xml_autofilter(data, ws, wb, idx)/*:string*/ {
|
|
|
|
var ref = typeof data.ref == "string" ? data.ref : encode_range(data.ref);
|
2019-11-01 03:09:14 +00:00
|
|
|
if(!wb.Workbook) wb.Workbook = ({Sheets:[]}/*:any*/);
|
2018-11-13 20:25:51 +00:00
|
|
|
if(!wb.Workbook.Names) wb.Workbook.Names = [];
|
|
|
|
var names/*: Array<any> */ = wb.Workbook.Names;
|
|
|
|
var range = decode_range(ref);
|
|
|
|
if(range.s.r == range.e.r) { range.e.r = decode_range(ws["!ref"]).e.r; ref = encode_range(range); }
|
|
|
|
for(var i = 0; i < names.length; ++i) {
|
|
|
|
var name = names[i];
|
|
|
|
if(name.Name != '_xlnm._FilterDatabase') continue;
|
|
|
|
if(name.Sheet != idx) continue;
|
2022-05-30 08:40:51 +00:00
|
|
|
name.Ref = formula_quote_sheet_name(wb.SheetNames[idx]) + "!" + fix_range(ref); break;
|
2018-11-13 20:25:51 +00:00
|
|
|
}
|
|
|
|
if(i == names.length) names.push({ Name: '_xlnm._FilterDatabase', Sheet: idx, Ref: "'" + wb.SheetNames[idx] + "'!" + ref });
|
|
|
|
return writextag("autoFilter", null, {ref:ref});
|
2017-04-10 05:10:54 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 07:28:03 +00:00
|
|
|
/* 18.3.1.88 sheetViews CT_SheetViews */
|
|
|
|
/* 18.3.1.87 sheetView CT_SheetView */
|
2022-05-25 01:45:55 +00:00
|
|
|
var sviewregex = /<(?:\w:)?sheetView(?:[^>a-z][^>]*)?\/?>/g;
|
2017-12-30 05:40:35 +00:00
|
|
|
function parse_ws_xml_sheetviews(data, wb/*:WBWBProps*/) {
|
2019-11-01 03:09:14 +00:00
|
|
|
if(!wb.Views) wb.Views = [{}];
|
|
|
|
(data.match(sviewregex)||[]).forEach(function(r/*:string*/, i/*:number*/) {
|
2017-12-30 05:40:35 +00:00
|
|
|
var tag = parsexmltag(r);
|
2019-11-01 03:09:14 +00:00
|
|
|
// $FlowIgnore
|
|
|
|
if(!wb.Views[i]) wb.Views[i] = {};
|
|
|
|
// $FlowIgnore
|
2021-05-13 19:02:31 +00:00
|
|
|
if(+tag.zoomScale) wb.Views[i].zoom = +tag.zoomScale;
|
|
|
|
// $FlowIgnore
|
2022-04-18 21:29:39 +00:00
|
|
|
if(tag.rightToLeft && parsexmlbool(tag.rightToLeft)) wb.Views[i].RTL = true;
|
2017-12-30 05:40:35 +00:00
|
|
|
});
|
|
|
|
}
|
2017-04-28 07:28:03 +00:00
|
|
|
function write_ws_xml_sheetviews(ws, opts, idx, wb)/*:string*/ {
|
2019-11-01 03:09:14 +00:00
|
|
|
var sview = ({workbookViewId:"0"}/*:any*/);
|
2017-12-25 02:25:03 +00:00
|
|
|
// $FlowIgnore
|
2019-11-01 03:09:14 +00:00
|
|
|
if((((wb||{}).Workbook||{}).Views||[])[0]) sview.rightToLeft = wb.Workbook.Views[0].RTL ? "1" : "0";
|
2017-12-25 02:25:03 +00:00
|
|
|
return writextag("sheetViews", writextag("sheetView", null, sview), {});
|
2017-04-28 07:28:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-23 09:07:51 +00:00
|
|
|
function write_ws_xml_cell(cell/*:Cell*/, ref, ws, opts/*::, idx, wb*/)/*:string*/ {
|
2022-03-14 06:51:33 +00:00
|
|
|
if(cell.c) ws['!comments'].push([ref, cell.c]);
|
2022-06-22 19:58:22 +00:00
|
|
|
if((cell.v === undefined || cell.t === "z" && !(opts||{}).sheetStubs) && typeof cell.f !== "string" && typeof cell.z == "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;
|
2019-11-01 03:09:14 +00:00
|
|
|
if(cell.t !== "z") switch(cell.t) {
|
2014-06-29 18:29:45 +00:00
|
|
|
case 'b': vv = cell.v ? "1" : "0"; break;
|
2023-04-23 07:58:36 +00:00
|
|
|
case 'n':
|
|
|
|
if(isNaN(cell.v)) { cell.t = "e"; vv = BErr[cell.v = 0x24]; } // #NUM!
|
|
|
|
else if(!isFinite(cell.v)) { cell.t = "e"; vv = BErr[cell.v = 0x07]; } // #DIV/0!
|
|
|
|
else vv = ''+cell.v; break;
|
2014-10-26 05:26:18 +00:00
|
|
|
case 'e': vv = BErr[cell.v]; break;
|
|
|
|
case 'd':
|
2019-11-01 03:09:14 +00:00
|
|
|
if(opts && opts.cellDates) vv = parseDate(cell.v, -1).toISOString();
|
2014-10-26 05:26:18 +00:00
|
|
|
else {
|
2017-10-17 00:14:32 +00:00
|
|
|
cell = dup(cell);
|
2014-10-26 05:26:18 +00:00
|
|
|
cell.t = 'n';
|
2017-03-23 01:18:40 +00:00
|
|
|
vv = ''+(cell.v = datenum(parseDate(cell.v)));
|
2014-10-26 05:26:18 +00:00
|
|
|
}
|
2022-03-20 01:54:41 +00:00
|
|
|
if(typeof cell.z === 'undefined') cell.z = table_fmt[14];
|
2014-10-26 05:26:18 +00:00
|
|
|
break;
|
2014-06-29 18:29:45 +00:00
|
|
|
default: vv = cell.v; break;
|
|
|
|
}
|
2022-05-25 01:45:55 +00:00
|
|
|
var v = (cell.t == "z" || cell.v == null)? "" : writetag('v', escapexml(vv)), o = ({r:ref}/*:any*/);
|
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;
|
2019-11-15 01:46:49 +00:00
|
|
|
case 'z': break;
|
2017-03-18 00:45:06 +00:00
|
|
|
default: if(cell.v == null) { delete cell.t; break; }
|
2021-09-22 06:45:08 +00:00
|
|
|
if(cell.v.length > 32767) throw new Error("Text length must not exceed 32767 characters");
|
2019-11-15 01:46:49 +00:00
|
|
|
if(opts && opts.bookSST) {
|
2018-06-22 21:40:01 +00:00
|
|
|
v = writetag('v', ''+get_sst_id(opts.Strings, cell.v, opts.revStrings));
|
2014-06-29 18:29:45 +00:00
|
|
|
o.t = "s"; break;
|
2014-06-05 07:06:20 +00:00
|
|
|
}
|
2022-05-25 01:45:55 +00:00
|
|
|
else 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; }
|
2020-09-09 00:18:48 +00:00
|
|
|
if(typeof cell.f == "string" && cell.f) {
|
2018-01-11 08:01:25 +00:00
|
|
|
var ff = cell.F && cell.F.slice(0, ref.length) == ref ? {t:"array", ref:cell.F} : null;
|
2017-03-18 00:45:06 +00:00
|
|
|
v = writextag('f', escapexml(cell.f), ff) + (cell.v != null ? v : "");
|
|
|
|
}
|
2022-09-23 17:36:38 +00:00
|
|
|
if(cell.l) {
|
|
|
|
cell.l.display = escapexml(vv);
|
|
|
|
ws['!links'].push([ref, cell.l]);
|
|
|
|
}
|
2022-03-03 08:35:39 +00:00
|
|
|
if(cell.D) o.cm = 1;
|
2014-06-29 18:29:45 +00:00
|
|
|
return writextag('c', v, o);
|
|
|
|
}
|
|
|
|
|
2022-03-12 14:05:57 +00:00
|
|
|
var parse_ws_xml_data = /*#__PURE__*/(function() {
|
2020-10-12 08:13:22 +00:00
|
|
|
var cellregex = /<(?:\w+:)?c[ \/>]/, rowregex = /<\/(?:\w+:)?row>/;
|
2017-02-10 19:23:01 +00:00
|
|
|
var rregex = /r=["']([^"']*)["']/, isregex = /<(?:\w+:)?is>([\S\s]*?)<\/(?:\w+:)?is>/;
|
2017-02-19 20:36:32 +00:00
|
|
|
var refregex = /ref=["']([^"']*)["']/;
|
2014-06-29 18:29:45 +00:00
|
|
|
var match_v = matchtag("v"), match_f = matchtag("f");
|
|
|
|
|
2017-12-30 05:40:35 +00:00
|
|
|
return function parse_ws_xml_data(sdata/*:string*/, s, opts, guess/*:Range*/, themes, styles) {
|
|
|
|
var ri = 0, x = "", cells/*:Array<string>*/ = [], cref/*:?Array<string>*/ = [], idx=0, i=0, cc=0, d="", p/*:any*/;
|
2014-10-10 02:22:38 +00:00
|
|
|
var tag, tagr = 0, tagc = 0;
|
2017-02-19 20:36:32 +00:00
|
|
|
var sstr, ftag;
|
2017-07-05 22:27:54 +00:00
|
|
|
var fmtid = 0, fillid = 0;
|
|
|
|
var do_format = Array.isArray(styles.CellXf), cf;
|
2017-12-30 05:40:35 +00:00
|
|
|
var arrayf/*:Array<[Range, string]>*/ = [];
|
2017-02-19 20:36:32 +00:00
|
|
|
var sharedf = [];
|
2022-10-24 01:05:59 +00:00
|
|
|
var dense = s["!data"] != null;
|
2017-12-30 05:40:35 +00:00
|
|
|
var rows/*:Array<RowInfo>*/ = [], rowobj = {}, rowrite = false;
|
2020-10-06 21:13:46 +00:00
|
|
|
var sheetStubs = !!opts.sheetStubs;
|
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 */
|
2021-09-23 07:19:42 +00:00
|
|
|
var rstarti = 0;
|
|
|
|
outa: for(ri = 0; ri < xlen; ++ri) switch(/*x.charCodeAt(ri)*/x[ri]) {
|
|
|
|
case ">" /*62*/:
|
|
|
|
if(/*x.charCodeAt(ri-1) != 47*/x[ri-1] != "/") { ++ri; break outa; }
|
|
|
|
if(opts && opts.cellStyles) {
|
|
|
|
// TODO: avoid duplication
|
|
|
|
tag = parsexmltag(x.slice(rstarti,ri), true);
|
|
|
|
tagr = tag.r != null ? parseInt(tag.r, 10) : tagr+1; tagc = -1;
|
|
|
|
if(opts.sheetRows && opts.sheetRows < tagr) continue;
|
|
|
|
rowobj = {}; rowrite = false;
|
|
|
|
if(tag.ht) { rowrite = true; rowobj.hpt = parseFloat(tag.ht); rowobj.hpx = pt2px(rowobj.hpt); }
|
2022-04-18 21:29:39 +00:00
|
|
|
if(tag.hidden && parsexmlbool(tag.hidden)) { rowrite = true; rowobj.hidden = true; }
|
2021-09-23 07:19:42 +00:00
|
|
|
if(tag.outlineLevel != null) { rowrite = true; rowobj.level = +tag.outlineLevel; }
|
|
|
|
if(rowrite) rows[tagr-1] = rowobj;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "<" /*60*/: rstarti = ri; break;
|
|
|
|
}
|
|
|
|
if(rstarti >= ri) break;
|
|
|
|
tag = parsexmltag(x.slice(rstarti,ri), true);
|
2017-04-26 02:27:12 +00:00
|
|
|
tagr = tag.r != null ? parseInt(tag.r, 10) : tagr+1; tagc = -1;
|
2014-07-28 13:22:32 +00:00
|
|
|
if(opts.sheetRows && opts.sheetRows < tagr) continue;
|
2022-11-17 09:35:34 +00:00
|
|
|
if(!opts.nodim) {
|
|
|
|
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
|
|
|
|
2017-04-28 07:28:03 +00:00
|
|
|
if(opts && opts.cellStyles) {
|
|
|
|
rowobj = {}; rowrite = false;
|
|
|
|
if(tag.ht) { rowrite = true; rowobj.hpt = parseFloat(tag.ht); rowobj.hpx = pt2px(rowobj.hpt); }
|
2022-04-18 21:29:39 +00:00
|
|
|
if(tag.hidden && parsexmlbool(tag.hidden)) { rowrite = true; rowobj.hidden = true; }
|
2017-07-09 17:37:45 +00:00
|
|
|
if(tag.outlineLevel != null) { rowrite = true; rowobj.level = +tag.outlineLevel; }
|
2017-04-28 07:28:03 +00:00
|
|
|
if(rowrite) rows[tagr-1] = rowobj;
|
|
|
|
}
|
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
/* 18.3.1.4 c CT_Cell */
|
2018-01-11 08:01:25 +00:00
|
|
|
cells = x.slice(ri).split(cellregex);
|
2019-11-01 03:09:14 +00:00
|
|
|
for(var rslice = 0; rslice != cells.length; ++rslice) if(cells[rslice].trim().charAt(0) != "<") break;
|
|
|
|
cells = cells.slice(rslice);
|
2017-02-22 06:57:59 +00:00
|
|
|
for(ri = 0; 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;
|
2018-01-11 08:01:25 +00:00
|
|
|
x = "<c " + (x.slice(0,1)=="<"?">":"") + x;
|
2017-02-10 19:23:01 +00:00
|
|
|
if(cref != null && cref.length === 2) {
|
2014-06-29 18:29:45 +00:00
|
|
|
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;
|
2018-01-11 08:01:25 +00:00
|
|
|
tag = parsexmltag(x.slice(0,i), true);
|
2017-04-17 02:08:23 +00:00
|
|
|
if(!tag.r) tag.r = encode_cell({r:tagr-1, c:tagc});
|
2018-01-11 08:01:25 +00:00
|
|
|
d = x.slice(i);
|
2017-02-10 19:23:01 +00:00
|
|
|
p = ({t:""}/*:any*/);
|
2014-06-29 18:29:45 +00:00
|
|
|
|
2017-02-19 20:36:32 +00:00
|
|
|
if((cref=d.match(match_v))!= null && /*::cref != null && */cref[1] !== '') p.v=unescapexml(cref[1]);
|
|
|
|
if(opts.cellFormula) {
|
2023-06-13 04:49:18 +00:00
|
|
|
if((cref=d.match(match_f))!= null /*:: && cref != null*/) {
|
|
|
|
if(cref[1] == "") {
|
|
|
|
if(/*::cref != null && cref[0] != null && */cref[0].indexOf('t="shared"') > -1) {
|
|
|
|
// TODO: parse formula
|
|
|
|
ftag = parsexmltag(cref[0]);
|
|
|
|
if(sharedf[ftag.si]) p.f = shift_formula_xlsx(sharedf[ftag.si][1], sharedf[ftag.si][2]/*[0].ref*/, tag.r);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* TODO: match against XLSXFutureFunctions */
|
|
|
|
p.f=unescapexml(utf8read(cref[1]), true);
|
|
|
|
if(!opts.xlfn) p.f = _xlfn(p.f);
|
|
|
|
if(/*::cref != null && cref[0] != null && */cref[0].indexOf('t="array"') > -1) {
|
|
|
|
p.F = (d.match(refregex)||[])[1];
|
|
|
|
if(p.F.indexOf(":") > -1) arrayf.push([safe_decode_range(p.F), p.F]);
|
|
|
|
} else if(/*::cref != null && cref[0] != null && */cref[0].indexOf('t="shared"') > -1) {
|
|
|
|
// TODO: parse formula
|
|
|
|
ftag = parsexmltag(cref[0]);
|
|
|
|
var ___f = unescapexml(utf8read(cref[1]));
|
|
|
|
if(!opts.xlfn) ___f = _xlfn(___f);
|
|
|
|
sharedf[parseInt(ftag.si, 10)] = [ftag, ___f, tag.r];
|
|
|
|
}
|
2017-02-19 20:36:32 +00:00
|
|
|
}
|
|
|
|
} else if((cref=d.match(/<f[^>]*\/>/))) {
|
|
|
|
ftag = parsexmltag(cref[0]);
|
2019-04-30 07:30:54 +00:00
|
|
|
if(sharedf[ftag.si]) p.f = shift_formula_xlsx(sharedf[ftag.si][1], sharedf[ftag.si][2]/*[0].ref*/, tag.r);
|
2017-02-19 20:36:32 +00:00
|
|
|
}
|
|
|
|
/* TODO: factor out contains logic */
|
|
|
|
var _tag = decode_cell(tag.r);
|
|
|
|
for(i = 0; i < arrayf.length; ++i)
|
|
|
|
if(_tag.r >= arrayf[i][0].s.r && _tag.r <= arrayf[i][0].e.r)
|
|
|
|
if(_tag.c >= arrayf[i][0].s.c && _tag.c <= arrayf[i][0].e.c)
|
|
|
|
p.F = arrayf[i][1];
|
|
|
|
}
|
2014-06-29 18:29:45 +00:00
|
|
|
|
2017-04-26 02:27:12 +00:00
|
|
|
if(tag.t == null && p.v === undefined) {
|
2017-05-11 07:29:59 +00:00
|
|
|
if(p.f || p.F) {
|
|
|
|
p.v = 0; p.t = "n";
|
2020-10-06 21:13:46 +00:00
|
|
|
} else if(!sheetStubs) continue;
|
2017-05-11 07:29:59 +00:00
|
|
|
else p.t = "z";
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
|
|
|
else p.t = tag.t || "n";
|
2018-07-25 06:38:32 +00:00
|
|
|
if(guess.s.c > tagc) guess.s.c = tagc;
|
|
|
|
if(guess.e.c < tagc) guess.e.c = tagc;
|
2014-06-29 18:29:45 +00:00
|
|
|
/* 18.18.11 t ST_CellType */
|
|
|
|
switch(p.t) {
|
2017-03-21 20:44:35 +00:00
|
|
|
case 'n':
|
2017-11-20 01:51:14 +00:00
|
|
|
if(p.v == "" || p.v == null) {
|
2020-10-06 21:13:46 +00:00
|
|
|
if(!sheetStubs) continue;
|
2017-11-20 01:51:14 +00:00
|
|
|
p.t = 'z';
|
|
|
|
} else p.v = parseFloat(p.v);
|
2017-03-21 20:44:35 +00:00
|
|
|
break;
|
2014-06-29 18:29:45 +00:00
|
|
|
case 's':
|
2017-03-10 01:09:18 +00:00
|
|
|
if(typeof p.v == 'undefined') {
|
2020-10-06 21:13:46 +00:00
|
|
|
if(!sheetStubs) continue;
|
2017-03-15 08:19:02 +00:00
|
|
|
p.t = 'z';
|
2017-07-05 22:27:54 +00:00
|
|
|
} else {
|
|
|
|
sstr = strs[parseInt(p.v, 10)];
|
|
|
|
p.v = sstr.t;
|
|
|
|
p.r = sstr.r;
|
|
|
|
if(opts.cellHTML) p.h = sstr.h;
|
2017-03-10 01:09:18 +00:00
|
|
|
}
|
2014-06-29 18:29:45 +00:00
|
|
|
break;
|
2014-10-26 05:26:18 +00:00
|
|
|
case 'str':
|
|
|
|
p.t = "s";
|
2022-04-20 17:31:11 +00:00
|
|
|
p.v = (p.v!=null) ? unescapexml(utf8read(p.v), true) : '';
|
2017-04-13 18:28:16 +00:00
|
|
|
if(opts.cellHTML) p.h = escapehtml(p.v);
|
2014-10-26 05:26:18 +00:00
|
|
|
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';
|
2019-11-01 03:09:14 +00:00
|
|
|
if(cref != null && (sstr = parse_si(cref[1]))) {
|
|
|
|
p.v = sstr.t;
|
|
|
|
if(opts.cellHTML) p.h = sstr.h;
|
|
|
|
} else p.v = "";
|
2017-04-10 05:10:54 +00:00
|
|
|
break;
|
2014-06-29 18:29:45 +00:00
|
|
|
case 'b': p.v = parsexmlbool(p.v); break;
|
|
|
|
case 'd':
|
2017-06-01 21:22:11 +00:00
|
|
|
if(opts.cellDates) p.v = parseDate(p.v, 1);
|
|
|
|
else { p.v = datenum(parseDate(p.v, 1)); p.t = 'n'; }
|
2014-06-29 18:29:45 +00:00
|
|
|
break;
|
2017-03-21 20:44:35 +00:00
|
|
|
/* error string in .w, number in .v */
|
2017-04-21 22:02:02 +00:00
|
|
|
case 'e':
|
2017-04-26 02:27:12 +00:00
|
|
|
if(!opts || opts.cellText !== false) p.w = p.v;
|
2017-04-21 22:02:02 +00:00
|
|
|
p.v = RBErr[p.v]; break;
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
|
|
|
/* formatting */
|
|
|
|
fmtid = fillid = 0;
|
2019-11-01 03:09:14 +00:00
|
|
|
cf = null;
|
2014-06-29 18:29:45 +00:00
|
|
|
if(do_format && tag.s !== undefined) {
|
|
|
|
cf = styles.CellXf[tag.s];
|
|
|
|
if(cf != null) {
|
|
|
|
if(cf.numFmtId != null) fmtid = cf.numFmtId;
|
2017-07-10 22:18:18 +00:00
|
|
|
if(opts.cellStyles) {
|
|
|
|
if(cf.fillId != null) fillid = cf.fillId;
|
|
|
|
}
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-18 23:25:50 +00:00
|
|
|
safe_format(p, fmtid, fillid, opts, themes, styles);
|
2022-03-20 01:54:41 +00:00
|
|
|
if(opts.cellDates && do_format && p.t == 'n' && fmt_is_date(table_fmt[fmtid])) { p.t = 'd'; p.v = numdate(p.v); }
|
2022-03-03 08:35:39 +00:00
|
|
|
if(tag.cm && opts.xlmeta) {
|
2022-03-14 06:51:33 +00:00
|
|
|
var cm = (opts.xlmeta.Cell||[])[+tag.cm-1];
|
|
|
|
if(cm && cm.type == 'XLDAPR') p.D = true;
|
2022-03-03 08:35:39 +00:00
|
|
|
}
|
2022-11-17 09:35:34 +00:00
|
|
|
var _r;
|
|
|
|
if(opts.nodim) {
|
|
|
|
_r = decode_cell(tag.r);
|
|
|
|
if(guess.s.r > _r.r) guess.s.r = _r.r;
|
|
|
|
if(guess.e.r < _r.r) guess.e.r = _r.r;
|
|
|
|
}
|
2017-04-08 06:55:35 +00:00
|
|
|
if(dense) {
|
2022-11-17 09:35:34 +00:00
|
|
|
_r = decode_cell(tag.r);
|
2022-10-24 01:05:59 +00:00
|
|
|
if(!s["!data"][_r.r]) s["!data"][_r.r] = [];
|
|
|
|
s["!data"][_r.r][_r.c] = p;
|
2017-04-08 06:55:35 +00:00
|
|
|
} else s[tag.r] = p;
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-28 07:28:03 +00:00
|
|
|
if(rows.length > 0) s['!rows'] = rows;
|
2014-06-29 18:29:45 +00:00
|
|
|
}; })();
|
|
|
|
|
2018-01-23 09:07:51 +00:00
|
|
|
function write_ws_xml_data(ws/*:Worksheet*/, opts, idx/*:number*/, wb/*:Workbook*//*::, rels*/)/*:string*/ {
|
2017-12-30 05:40:35 +00:00
|
|
|
var o/*:Array<string>*/ = [], r/*:Array<string>*/ = [], range = safe_decode_range(ws['!ref']), cell="", ref, rr = "", cols/*:Array<string>*/ = [], R=0, C=0, rows = ws['!rows'];
|
2022-10-24 01:05:59 +00:00
|
|
|
var dense = ws["!data"] != null;
|
2017-10-17 00:14:32 +00:00
|
|
|
var params = ({r:rr}/*:any*/), row/*:RowInfo*/, height = -1;
|
2014-07-28 13:22:32 +00:00
|
|
|
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;
|
2022-10-24 01:05:59 +00:00
|
|
|
var _cell = dense ? (ws["!data"][R]||[])[C]: ws[ref];
|
2017-04-08 06:55:35 +00:00
|
|
|
if(_cell === undefined) continue;
|
|
|
|
if((cell = write_ws_xml_cell(_cell, ref, ws, opts, idx, wb)) != null) r.push(cell);
|
2014-05-16 00:33:34 +00:00
|
|
|
}
|
2018-02-08 18:21:39 +00:00
|
|
|
if(r.length > 0 || (rows && rows[R])) {
|
2017-10-17 00:14:32 +00:00
|
|
|
params = ({r:rr}/*:any*/);
|
2017-03-31 03:57:11 +00:00
|
|
|
if(rows && rows[R]) {
|
2017-10-17 00:14:32 +00:00
|
|
|
row = rows[R];
|
2017-03-31 03:57:11 +00:00
|
|
|
if(row.hidden) params.hidden = 1;
|
2017-10-17 00:14:32 +00:00
|
|
|
height = -1;
|
2019-04-01 14:25:15 +00:00
|
|
|
if(row.hpx) height = px2pt(row.hpx);
|
|
|
|
else if(row.hpt) height = row.hpt;
|
|
|
|
if(height > -1) { params.ht = height; params.customHeight = 1; }
|
|
|
|
if(row.level) { params.outlineLevel = row.level; }
|
2017-03-31 03:57:11 +00:00
|
|
|
}
|
|
|
|
o[o.length] = (writextag('row', r.join(""), params));
|
|
|
|
}
|
2014-05-16 00:33:34 +00:00
|
|
|
}
|
2017-07-09 17:37:45 +00:00
|
|
|
if(rows) for(; R < rows.length; ++R) {
|
|
|
|
if(rows && rows[R]) {
|
2017-07-26 08:35:28 +00:00
|
|
|
params = ({r:R+1}/*:any*/);
|
|
|
|
row = rows[R];
|
2017-07-09 17:37:45 +00:00
|
|
|
if(row.hidden) params.hidden = 1;
|
2017-07-26 08:35:28 +00:00
|
|
|
height = -1;
|
2017-07-09 17:37:45 +00:00
|
|
|
if (row.hpx) height = px2pt(row.hpx);
|
|
|
|
else if (row.hpt) height = row.hpt;
|
|
|
|
if (height > -1) { params.ht = height; params.customHeight = 1; }
|
|
|
|
if (row.level) { params.outlineLevel = row.level; }
|
|
|
|
o[o.length] = (writextag('row', "", params));
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2017-03-31 00:47:35 +00:00
|
|
|
function write_ws_xml(idx/*:number*/, opts, wb/*:Workbook*/, rels)/*:string*/ {
|
2022-03-11 05:29:05 +00:00
|
|
|
var o = [XML_HEADER, writextag('worksheet', null, {
|
2022-03-12 14:05:57 +00:00
|
|
|
'xmlns': XMLNS_main[0],
|
2022-03-11 05:29:05 +00:00
|
|
|
'xmlns:r': XMLNS.r
|
|
|
|
})];
|
2014-07-28 13:22:32 +00:00
|
|
|
var s = wb.SheetNames[idx], sidx = 0, rdata = "";
|
|
|
|
var ws = wb.Sheets[s];
|
2017-04-10 05:10:54 +00:00
|
|
|
if(ws == null) ws = {};
|
2018-04-27 20:11:18 +00:00
|
|
|
var ref = ws['!ref'] || 'A1';
|
|
|
|
var range = safe_decode_range(ref);
|
|
|
|
if(range.e.c > 0x3FFF || range.e.r > 0xFFFFF) {
|
|
|
|
if(opts.WTF) throw new Error("Range " + ref + " exceeds format limit A1:XFD1048576");
|
|
|
|
range.e.c = Math.min(range.e.c, 0x3FFF);
|
|
|
|
range.e.r = Math.min(range.e.c, 0xFFFFF);
|
|
|
|
ref = encode_range(range);
|
|
|
|
}
|
2017-03-31 00:47:35 +00:00
|
|
|
if(!rels) rels = {};
|
2017-04-02 06:47:25 +00:00
|
|
|
ws['!comments'] = [];
|
2019-11-15 01:46:49 +00:00
|
|
|
var _drawing = [];
|
2017-03-31 00:47:35 +00:00
|
|
|
|
2019-11-15 01:46:49 +00:00
|
|
|
write_ws_xml_sheetpr(ws, wb, idx, opts, o);
|
2017-04-10 05:10:54 +00:00
|
|
|
|
2014-07-28 13:22:32 +00:00
|
|
|
o[o.length] = (writextag('dimension', null, {'ref': ref}));
|
|
|
|
|
2017-04-28 07:28:03 +00:00
|
|
|
o[o.length] = write_ws_xml_sheetviews(ws, opts, idx, wb);
|
2017-04-10 05:10:54 +00:00
|
|
|
|
2017-03-31 03:23:52 +00:00
|
|
|
/* TODO: store in WB, process styles */
|
2017-07-09 17:37:45 +00:00
|
|
|
if(opts.sheetFormat) o[o.length] = (writextag('sheetFormatPr', null, {
|
|
|
|
defaultRowHeight:opts.sheetFormat.defaultRowHeight||'16',
|
|
|
|
baseColWidth:opts.sheetFormat.baseColWidth||'10',
|
|
|
|
outlineLevelRow:opts.sheetFormat.outlineLevelRow||'7'
|
|
|
|
}));
|
2017-03-31 03:23:52 +00:00
|
|
|
|
2017-04-10 05:10:54 +00:00
|
|
|
if(ws['!cols'] != null && ws['!cols'].length > 0) o[o.length] = (write_ws_xml_cols(ws, ws['!cols']));
|
|
|
|
|
2014-07-28 13:22:32 +00:00
|
|
|
o[sidx = o.length] = '<sheetData/>';
|
2017-03-31 00:47:35 +00:00
|
|
|
ws['!links'] = [];
|
2017-03-28 22:03:03 +00:00
|
|
|
if(ws['!ref'] != null) {
|
2017-03-31 00:47:35 +00:00
|
|
|
rdata = write_ws_xml_data(ws, opts, idx, wb, rels);
|
2014-07-28 13:22:32 +00:00
|
|
|
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
|
|
|
|
2017-04-10 05:10:54 +00:00
|
|
|
/* sheetCalcPr */
|
|
|
|
|
2021-11-04 05:14:09 +00:00
|
|
|
if(ws['!protect']) o[o.length] = write_ws_xml_protection(ws['!protect']);
|
2017-04-04 18:41:11 +00:00
|
|
|
|
2017-04-10 05:10:54 +00:00
|
|
|
/* protectedRanges */
|
|
|
|
/* scenarios */
|
|
|
|
|
2018-11-13 20:25:51 +00:00
|
|
|
if(ws['!autofilter'] != null) o[o.length] = write_ws_xml_autofilter(ws['!autofilter'], ws, wb, idx);
|
2017-04-10 05:10:54 +00:00
|
|
|
|
|
|
|
/* sortState */
|
|
|
|
/* dataConsolidate */
|
|
|
|
/* customSheetViews */
|
|
|
|
|
2017-03-28 22:03:03 +00:00
|
|
|
if(ws['!merges'] != null && ws['!merges'].length > 0) o[o.length] = (write_ws_xml_merges(ws['!merges']));
|
2014-08-26 17:40:04 +00:00
|
|
|
|
2017-04-10 05:10:54 +00:00
|
|
|
/* phoneticPr */
|
|
|
|
/* conditionalFormatting */
|
|
|
|
/* dataValidations */
|
|
|
|
|
2017-04-02 06:47:25 +00:00
|
|
|
var relc = -1, rel, rId = -1;
|
2019-11-01 03:09:14 +00:00
|
|
|
if(/*::(*/ws['!links']/*::||[])*/.length > 0) {
|
2017-03-31 00:47:35 +00:00
|
|
|
o[o.length] = "<hyperlinks>";
|
2019-11-01 03:09:14 +00:00
|
|
|
/*::(*/ws['!links']/*::||[])*/.forEach(function(l) {
|
2017-03-31 00:47:35 +00:00
|
|
|
if(!l[1].Target) return;
|
2017-12-15 01:18:40 +00:00
|
|
|
rel = ({"ref":l[0]}/*:any*/);
|
|
|
|
if(l[1].Target.charAt(0) != "#") {
|
|
|
|
rId = add_rels(rels, -1, escapexml(l[1].Target).replace(/#.*$/, ""), RELS.HLINK);
|
|
|
|
rel["r:id"] = "rId"+rId;
|
|
|
|
}
|
2018-01-11 08:01:25 +00:00
|
|
|
if((relc = l[1].Target.indexOf("#")) > -1) rel.location = escapexml(l[1].Target.slice(relc+1));
|
2017-03-31 00:47:35 +00:00
|
|
|
if(l[1].Tooltip) rel.tooltip = escapexml(l[1].Tooltip);
|
2022-09-23 17:36:38 +00:00
|
|
|
rel.display = l[1].display;
|
2017-03-31 00:47:35 +00:00
|
|
|
o[o.length] = writextag("hyperlink",null,rel);
|
|
|
|
});
|
|
|
|
o[o.length] = "</hyperlinks>";
|
|
|
|
}
|
2017-03-28 22:03:03 +00:00
|
|
|
delete ws['!links'];
|
2017-04-02 06:47:25 +00:00
|
|
|
|
2017-04-10 05:10:54 +00:00
|
|
|
/* printOptions */
|
|
|
|
|
2019-11-15 01:46:49 +00:00
|
|
|
if(ws['!margins'] != null) o[o.length] = write_ws_xml_margins(ws['!margins']);
|
2017-04-08 06:55:35 +00:00
|
|
|
|
2019-11-15 01:46:49 +00:00
|
|
|
/* pageSetup */
|
|
|
|
/* headerFooter */
|
2017-04-10 05:10:54 +00:00
|
|
|
/* rowBreaks */
|
|
|
|
/* colBreaks */
|
|
|
|
/* customProperties */
|
|
|
|
/* cellWatches */
|
2018-02-14 20:06:35 +00:00
|
|
|
|
2018-08-15 19:22:47 +00:00
|
|
|
if(!opts || opts.ignoreEC || (opts.ignoreEC == (void 0))) o[o.length] = writetag("ignoredErrors", writextag("ignoredError", null, {numberStoredAsText:1, sqref:ref}));
|
2018-02-14 20:06:35 +00:00
|
|
|
|
2017-04-10 05:10:54 +00:00
|
|
|
/* smartTags */
|
|
|
|
|
2019-11-15 01:46:49 +00:00
|
|
|
if(_drawing.length > 0) {
|
2017-04-08 06:55:35 +00:00
|
|
|
rId = add_rels(rels, -1, "../drawings/drawing" + (idx+1) + ".xml", RELS.DRAW);
|
|
|
|
o[o.length] = writextag("drawing", null, {"r:id":"rId" + rId});
|
2019-11-15 01:46:49 +00:00
|
|
|
ws['!drawing'] = _drawing;
|
2017-04-08 06:55:35 +00:00
|
|
|
}
|
2017-04-10 05:10:54 +00:00
|
|
|
|
2017-04-02 06:47:25 +00:00
|
|
|
if(ws['!comments'].length > 0) {
|
|
|
|
rId = add_rels(rels, -1, "../drawings/vmlDrawing" + (idx+1) + ".vml", RELS.VML);
|
|
|
|
o[o.length] = writextag("legacyDrawing", null, {"r:id":"rId" + rId});
|
|
|
|
ws['!legacy'] = rId;
|
|
|
|
}
|
|
|
|
|
2019-11-15 01:46:49 +00:00
|
|
|
/* legacyDrawingHF */
|
2017-04-10 05:10:54 +00:00
|
|
|
/* picture */
|
|
|
|
/* oleObjects */
|
|
|
|
/* controls */
|
|
|
|
/* webPublishItems */
|
|
|
|
/* tableParts */
|
2019-11-15 01:46:49 +00:00
|
|
|
/* extLst */
|
2017-04-10 05:10:54 +00:00
|
|
|
|
2019-11-15 01:46:49 +00:00
|
|
|
if(o.length>1) { 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
|
|
|
}
|