2019-11-15 01:46:49 +00:00
|
|
|
/* 18.4.7 rPr CT_RPrElt */
|
|
|
|
function parse_rpr(rpr) {
|
|
|
|
var font = {}, m = rpr.match(tagregex), i = 0;
|
|
|
|
var pass = false;
|
|
|
|
if(m) for(;i!=m.length; ++i) {
|
|
|
|
var y = parsexmltag(m[i]);
|
|
|
|
switch(y[0].replace(/\w*:/g,"")) {
|
|
|
|
/* 18.8.12 condense CT_BooleanProperty */
|
|
|
|
/* ** not required . */
|
|
|
|
case '<condense': break;
|
|
|
|
/* 18.8.17 extend CT_BooleanProperty */
|
|
|
|
/* ** not required . */
|
|
|
|
case '<extend': break;
|
|
|
|
/* 18.8.36 shadow CT_BooleanProperty */
|
|
|
|
/* ** not required . */
|
|
|
|
case '<shadow':
|
|
|
|
if(!y.val) break;
|
|
|
|
/* falls through */
|
|
|
|
case '<shadow>':
|
|
|
|
case '<shadow/>': font.shadow = 1; break;
|
|
|
|
case '</shadow>': break;
|
|
|
|
|
|
|
|
/* 18.4.1 charset CT_IntProperty TODO */
|
|
|
|
case '<charset':
|
|
|
|
if(y.val == '1') break;
|
|
|
|
font.cp = CS2CP[parseInt(y.val, 10)];
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* 18.4.2 outline CT_BooleanProperty TODO */
|
|
|
|
case '<outline':
|
|
|
|
if(!y.val) break;
|
|
|
|
/* falls through */
|
|
|
|
case '<outline>':
|
|
|
|
case '<outline/>': font.outline = 1; break;
|
|
|
|
case '</outline>': break;
|
|
|
|
|
|
|
|
/* 18.4.5 rFont CT_FontName */
|
|
|
|
case '<rFont': font.name = y.val; break;
|
|
|
|
|
|
|
|
/* 18.4.11 sz CT_FontSize */
|
|
|
|
case '<sz': font.sz = y.val; break;
|
|
|
|
|
|
|
|
/* 18.4.10 strike CT_BooleanProperty */
|
|
|
|
case '<strike':
|
|
|
|
if(!y.val) break;
|
|
|
|
/* falls through */
|
|
|
|
case '<strike>':
|
|
|
|
case '<strike/>': font.strike = 1; break;
|
|
|
|
case '</strike>': break;
|
|
|
|
|
|
|
|
/* 18.4.13 u CT_UnderlineProperty */
|
|
|
|
case '<u':
|
|
|
|
if(!y.val) break;
|
|
|
|
switch(y.val) {
|
|
|
|
case 'double': font.uval = "double"; break;
|
|
|
|
case 'singleAccounting': font.uval = "single-accounting"; break;
|
|
|
|
case 'doubleAccounting': font.uval = "double-accounting"; break;
|
|
|
|
}
|
|
|
|
/* falls through */
|
|
|
|
case '<u>':
|
|
|
|
case '<u/>': font.u = 1; break;
|
|
|
|
case '</u>': break;
|
|
|
|
|
|
|
|
/* 18.8.2 b */
|
|
|
|
case '<b':
|
|
|
|
if(y.val == '0') break;
|
|
|
|
/* falls through */
|
|
|
|
case '<b>':
|
|
|
|
case '<b/>': font.b = 1; break;
|
|
|
|
case '</b>': break;
|
|
|
|
|
|
|
|
/* 18.8.26 i */
|
|
|
|
case '<i':
|
|
|
|
if(y.val == '0') break;
|
|
|
|
/* falls through */
|
|
|
|
case '<i>':
|
|
|
|
case '<i/>': font.i = 1; break;
|
|
|
|
case '</i>': break;
|
|
|
|
|
|
|
|
/* 18.3.1.15 color CT_Color TODO: tint, theme, auto, indexed */
|
|
|
|
case '<color':
|
|
|
|
if(y.rgb) font.color = y.rgb.slice(2,8);
|
|
|
|
break;
|
2022-02-01 05:58:45 +00:00
|
|
|
case '<color>': case '<color/>': case '</color>': break;
|
2019-11-15 01:46:49 +00:00
|
|
|
|
|
|
|
/* 18.8.18 family ST_FontFamily */
|
|
|
|
case '<family': font.family = y.val; break;
|
2022-02-01 05:58:45 +00:00
|
|
|
case '<family>': case '<family/>': case '</family>': break;
|
2019-11-15 01:46:49 +00:00
|
|
|
|
|
|
|
/* 18.4.14 vertAlign CT_VerticalAlignFontProperty TODO */
|
|
|
|
case '<vertAlign': font.valign = y.val; break;
|
2022-02-01 05:58:45 +00:00
|
|
|
case '<vertAlign>': case '<vertAlign/>': case '</vertAlign>': break;
|
2019-11-15 01:46:49 +00:00
|
|
|
|
|
|
|
/* 18.8.35 scheme CT_FontScheme TODO */
|
|
|
|
case '<scheme': break;
|
2022-02-01 05:58:45 +00:00
|
|
|
case '<scheme>': case '<scheme/>': case '</scheme>': break;
|
2019-11-15 01:46:49 +00:00
|
|
|
|
|
|
|
/* 18.2.10 extLst CT_ExtensionList ? */
|
|
|
|
case '<extLst': case '<extLst>': case '</extLst>': break;
|
|
|
|
case '<ext': pass = true; break;
|
|
|
|
case '</ext>': pass = false; break;
|
|
|
|
default:
|
|
|
|
if(y[0].charCodeAt(1) !== 47 && !pass) throw new Error('Unrecognized rich format ' + y[0]);
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2019-11-15 01:46:49 +00:00
|
|
|
}
|
|
|
|
return font;
|
|
|
|
}
|
|
|
|
|
2022-03-12 14:05:57 +00:00
|
|
|
var parse_rs = /*#__PURE__*/(function() {
|
2019-11-15 01:46:49 +00:00
|
|
|
var tregex = matchtag("t"), rpregex = matchtag("rPr");
|
|
|
|
/* 18.4.4 r CT_RElt */
|
|
|
|
function parse_r(r) {
|
|
|
|
/* 18.4.12 t ST_Xstring */
|
|
|
|
var t = r.match(tregex)/*, cp = 65001*/;
|
|
|
|
if(!t) return {t:"s", v:""};
|
|
|
|
|
|
|
|
var o/*:Cell*/ = ({t:'s', v:unescapexml(t[1])}/*:any*/);
|
|
|
|
var rpr = r.match(rpregex);
|
|
|
|
if(rpr) o.s = parse_rpr(rpr[1]);
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
var rregex = /<(?:\w+:)?r>/g, rend = /<\/(?:\w+:)?r>/;
|
|
|
|
return function parse_rs(rs) {
|
|
|
|
return rs.replace(rregex,"").split(rend).map(parse_r).filter(function(r) { return r.v; });
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
|
|
/* Parse a list of <r> tags */
|
2022-03-12 14:05:57 +00:00
|
|
|
var rs_to_html = /*#__PURE__*/(function parse_rs_factory() {
|
2019-11-15 01:46:49 +00:00
|
|
|
var nlregex = /(\r\n|\n)/g;
|
|
|
|
function parse_rpr2(font, intro, outro) {
|
2017-12-30 05:40:35 +00:00
|
|
|
var style/*:Array<string>*/ = [];
|
2017-04-20 03:24:48 +00:00
|
|
|
|
|
|
|
if(font.u) style.push("text-decoration: underline;");
|
|
|
|
if(font.uval) style.push("text-underline-style:" + font.uval + ";");
|
2018-04-17 20:01:57 +00:00
|
|
|
if(font.sz) style.push("font-size:" + font.sz + "pt;");
|
2017-04-20 03:24:48 +00:00
|
|
|
if(font.outline) style.push("text-effect: outline;");
|
|
|
|
if(font.shadow) style.push("text-shadow: auto;");
|
2014-01-18 13:45:49 +00:00
|
|
|
intro.push('<span style="' + style.join("") + '">');
|
2017-04-20 03:24:48 +00:00
|
|
|
|
|
|
|
if(font.b) { intro.push("<b>"); outro.push("</b>"); }
|
|
|
|
if(font.i) { intro.push("<i>"); outro.push("</i>"); }
|
|
|
|
if(font.strike) { intro.push("<s>"); outro.push("</s>"); }
|
|
|
|
|
2019-11-15 01:46:49 +00:00
|
|
|
var align = font.valign || "";
|
|
|
|
if(align == "superscript" || align == "super") align = "sup";
|
2017-04-20 03:24:48 +00:00
|
|
|
else if(align == "subscript") align = "sub";
|
|
|
|
if(align != "") { intro.push("<" + align + ">"); outro.push("</" + align + ">"); }
|
|
|
|
|
2014-01-18 13:45:49 +00:00
|
|
|
outro.push("</span>");
|
2019-11-15 01:46:49 +00:00
|
|
|
return font;
|
|
|
|
}
|
2013-05-02 16:59:27 +00:00
|
|
|
|
2014-01-18 13:45:49 +00:00
|
|
|
/* 18.4.4 r CT_RElt */
|
2019-11-15 01:46:49 +00:00
|
|
|
function r_to_html(r) {
|
|
|
|
var terms/*:[Array<string>, string, Array<string>]*/ = [[],r.v,[]];
|
|
|
|
if(!r.v) return "";
|
2014-01-18 13:45:49 +00:00
|
|
|
|
2019-11-15 01:46:49 +00:00
|
|
|
if(r.s) parse_rpr2(r.s, terms[0], terms[2]);
|
2014-04-23 01:37:08 +00:00
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
return terms[0].join("") + terms[1].replace(nlregex,'<br/>') + terms[2].join("");
|
2014-01-18 13:45:49 +00:00
|
|
|
}
|
2019-11-15 01:46:49 +00:00
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
return function parse_rs(rs) {
|
2019-11-15 01:46:49 +00:00
|
|
|
return rs.map(r_to_html).join("");
|
2014-01-18 13:45:49 +00:00
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
/* 18.4.8 si CT_Rst */
|
2017-02-10 19:23:01 +00:00
|
|
|
var sitregex = /<(?:\w+:)?t[^>]*>([^<]*)<\/(?:\w+:)?t>/g, sirregex = /<(?:\w+:)?r>/;
|
2017-07-05 22:27:54 +00:00
|
|
|
var sirphregex = /<(?:\w+:)?rPh.*?>([\s\S]*?)<\/(?:\w+:)?rPh>/g;
|
2014-06-29 18:29:45 +00:00
|
|
|
function parse_si(x, opts) {
|
2014-02-12 06:09:42 +00:00
|
|
|
var html = opts ? opts.cellHTML : true;
|
2014-01-18 13:45:49 +00:00
|
|
|
var z = {};
|
2020-08-12 11:31:24 +00:00
|
|
|
if(!x) return { t: "" };
|
2018-01-23 09:07:51 +00:00
|
|
|
//var y;
|
2014-01-18 13:45:49 +00:00
|
|
|
/* 18.4.12 t ST_Xstring (Plaintext String) */
|
2017-02-19 20:36:32 +00:00
|
|
|
// TODO: is whitespace actually valid here?
|
|
|
|
if(x.match(/^\s*<(?:\w+:)?t[^>]*>/)) {
|
2017-09-22 22:18:51 +00:00
|
|
|
z.t = unescapexml(utf8read(x.slice(x.indexOf(">")+1).split(/<\/(?:\w+:)?t>/)[0]||""));
|
2017-02-19 20:36:32 +00:00
|
|
|
z.r = utf8read(x);
|
2017-04-13 18:28:16 +00:00
|
|
|
if(html) z.h = escapehtml(z.t);
|
2014-01-18 13:45:49 +00:00
|
|
|
}
|
|
|
|
/* 18.4.4 r CT_RElt (Rich Text Run) */
|
2018-01-23 09:07:51 +00:00
|
|
|
else if((/*y = */x.match(sirregex))) {
|
2017-02-19 20:36:32 +00:00
|
|
|
z.r = utf8read(x);
|
2017-09-22 22:18:51 +00:00
|
|
|
z.t = unescapexml(utf8read((x.replace(sirphregex, '').match(sitregex)||[]).join("").replace(tagregex,"")));
|
2019-11-15 01:46:49 +00:00
|
|
|
if(html) z.h = rs_to_html(parse_rs(z.r));
|
2014-01-18 13:45:49 +00:00
|
|
|
}
|
|
|
|
/* 18.4.3 phoneticPr CT_PhoneticPr (TODO: needed for Asian support) */
|
|
|
|
/* 18.4.6 rPh CT_PhoneticRun (TODO: needed for Asian support) */
|
|
|
|
return z;
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2013-05-02 16:59:27 +00:00
|
|
|
|
2014-01-18 13:45:49 +00:00
|
|
|
/* 18.4 Shared String Table */
|
2017-02-10 19:23:01 +00:00
|
|
|
var sstr0 = /<(?:\w+:)?sst([^>]*)>([\s\S]*)<\/(?:\w+:)?sst>/;
|
|
|
|
var sstr1 = /<(?:\w+:)?(?:si|sstItem)>/g;
|
|
|
|
var sstr2 = /<\/(?:\w+:)?(?:si|sstItem)>/;
|
|
|
|
function parse_sst_xml(data/*:string*/, opts)/*:SST*/ {
|
|
|
|
var s/*:SST*/ = ([]/*:any*/), ss = "";
|
|
|
|
if(!data) return s;
|
2014-01-28 16:38:02 +00:00
|
|
|
/* 18.4.9 sst CT_Sst */
|
2014-06-29 18:29:45 +00:00
|
|
|
var sst = data.match(sstr0);
|
2017-12-30 05:40:35 +00:00
|
|
|
if(sst) {
|
2014-06-29 18:29:45 +00:00
|
|
|
ss = sst[2].replace(sstr1,"").split(sstr2);
|
|
|
|
for(var i = 0; i != ss.length; ++i) {
|
2017-02-19 20:36:32 +00:00
|
|
|
var o = parse_si(ss[i].trim(), opts);
|
2014-06-29 18:29:45 +00:00
|
|
|
if(o != null) s[s.length] = o;
|
|
|
|
}
|
2014-01-28 16:38:02 +00:00
|
|
|
sst = parsexmltag(sst[1]); s.Count = sst.count; s.Unique = sst.uniqueCount;
|
|
|
|
}
|
|
|
|
return s;
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2014-05-16 00:33:34 +00:00
|
|
|
RELS.SST = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings";
|
2014-07-28 13:22:32 +00:00
|
|
|
var straywsregex = /^\s|\s$|[\t\n\r]/;
|
2017-02-10 19:23:01 +00:00
|
|
|
function write_sst_xml(sst/*:SST*/, opts)/*:string*/ {
|
2014-05-16 00:33:34 +00:00
|
|
|
if(!opts.bookSST) return "";
|
2014-06-29 18:29:45 +00:00
|
|
|
var o = [XML_HEADER];
|
|
|
|
o[o.length] = (writextag('sst', null, {
|
2022-03-12 14:05:57 +00:00
|
|
|
xmlns: XMLNS_main[0],
|
2014-05-16 00:33:34 +00:00
|
|
|
count: sst.Count,
|
|
|
|
uniqueCount: sst.Unique
|
|
|
|
}));
|
2014-06-29 18:29:45 +00:00
|
|
|
for(var i = 0; i != sst.length; ++i) { if(sst[i] == null) continue;
|
2017-03-12 18:02:43 +00:00
|
|
|
var s/*:XLString*/ = sst[i];
|
2014-05-22 12:16:51 +00:00
|
|
|
var sitag = "<si>";
|
|
|
|
if(s.r) sitag += s.r;
|
|
|
|
else {
|
|
|
|
sitag += "<t";
|
2017-03-22 15:21:01 +00:00
|
|
|
if(!s.t) s.t = "";
|
2014-07-28 13:22:32 +00:00
|
|
|
if(s.t.match(straywsregex)) sitag += ' xml:space="preserve"';
|
2014-06-29 18:29:45 +00:00
|
|
|
sitag += ">" + escapexml(s.t) + "</t>";
|
2014-05-22 12:16:51 +00:00
|
|
|
}
|
|
|
|
sitag += "</si>";
|
2014-06-29 18:29:45 +00:00
|
|
|
o[o.length] = (sitag);
|
|
|
|
}
|
|
|
|
if(o.length>2){ o[o.length] = ('</sst>'); o[1]=o[1].replace("/>",">"); }
|
2014-05-16 00:33:34 +00:00
|
|
|
return o.join("");
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|