2014-05-16 00:33:34 +00:00
|
|
|
|
/* 15.2.12.3 Extended File Properties Part */
|
|
|
|
|
/* [MS-OSHARED] 2.3.3.2.[1-2].1 (PIDSI/PIDDSI) */
|
2017-02-10 19:23:01 +00:00
|
|
|
|
var EXT_PROPS/*:Array<Array<string> >*/ = [
|
2014-05-16 00:33:34 +00:00
|
|
|
|
["Application", "Application", "string"],
|
|
|
|
|
["AppVersion", "AppVersion", "string"],
|
|
|
|
|
["Company", "Company", "string"],
|
|
|
|
|
["DocSecurity", "DocSecurity", "string"],
|
|
|
|
|
["Manager", "Manager", "string"],
|
|
|
|
|
["HyperlinksChanged", "HyperlinksChanged", "bool"],
|
|
|
|
|
["SharedDoc", "SharedDoc", "bool"],
|
|
|
|
|
["LinksUpToDate", "LinksUpToDate", "bool"],
|
|
|
|
|
["ScaleCrop", "ScaleCrop", "bool"],
|
|
|
|
|
["HeadingPairs", "HeadingPairs", "raw"],
|
2014-06-03 18:39:46 +00:00
|
|
|
|
["TitlesOfParts", "TitlesOfParts", "raw"]
|
2014-05-16 00:33:34 +00:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
XMLNS.EXT_PROPS = "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties";
|
|
|
|
|
RELS.EXT_PROPS = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties';
|
|
|
|
|
|
2018-05-05 06:34:37 +00:00
|
|
|
|
var PseudoPropsPairs = [
|
|
|
|
|
"Worksheets", "SheetNames",
|
|
|
|
|
"NamedRanges", "DefinedNames",
|
|
|
|
|
"Chartsheets", "ChartNames"
|
|
|
|
|
];
|
|
|
|
|
function load_props_pairs(HP/*:string|Array<Array<any>>*/, TOP, props, opts) {
|
|
|
|
|
var v = [];
|
|
|
|
|
if(typeof HP == "string") v = parseVector(HP, opts);
|
|
|
|
|
else for(var j = 0; j < HP.length; ++j) v = v.concat(HP[j].map(function(hp) { return {v:hp}; }));
|
|
|
|
|
var parts = (typeof TOP == "string") ? parseVector(TOP, opts).map(function (x) { return x.v; }) : TOP;
|
|
|
|
|
var idx = 0, len = 0;
|
|
|
|
|
if(parts.length > 0) for(var i = 0; i !== v.length; i += 2) {
|
|
|
|
|
len = +(v[i+1].v);
|
|
|
|
|
switch(v[i].v) {
|
|
|
|
|
case "Worksheets":
|
|
|
|
|
case "工作表":
|
|
|
|
|
case "Листы":
|
|
|
|
|
case "أوراق العمل":
|
|
|
|
|
case "ワークシート":
|
|
|
|
|
case "גליונות עבודה":
|
|
|
|
|
case "Arbeitsblätter":
|
|
|
|
|
case "Çalışma Sayfaları":
|
|
|
|
|
case "Feuilles de calcul":
|
|
|
|
|
case "Fogli di lavoro":
|
|
|
|
|
case "Folhas de cálculo":
|
|
|
|
|
case "Planilhas":
|
|
|
|
|
case "Regneark":
|
2019-11-01 03:09:14 +00:00
|
|
|
|
case "Hojas de cálculo":
|
2018-05-05 06:34:37 +00:00
|
|
|
|
case "Werkbladen":
|
|
|
|
|
props.Worksheets = len;
|
|
|
|
|
props.SheetNames = parts.slice(idx, idx + len);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "Named Ranges":
|
2019-11-01 03:09:14 +00:00
|
|
|
|
case "Rangos con nombre":
|
2018-05-05 06:34:37 +00:00
|
|
|
|
case "名前付き一覧":
|
|
|
|
|
case "Benannte Bereiche":
|
|
|
|
|
case "Navngivne områder":
|
|
|
|
|
props.NamedRanges = len;
|
|
|
|
|
props.DefinedNames = parts.slice(idx, idx + len);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "Charts":
|
|
|
|
|
case "Diagramme":
|
|
|
|
|
props.Chartsheets = len;
|
|
|
|
|
props.ChartNames = parts.slice(idx, idx + len);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
idx += len;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-03 15:51:16 +00:00
|
|
|
|
function parse_ext_props(data, p, opts) {
|
2014-05-16 00:33:34 +00:00
|
|
|
|
var q = {}; if(!p) p = {};
|
2017-09-30 06:18:11 +00:00
|
|
|
|
data = utf8read(data);
|
2014-05-16 00:33:34 +00:00
|
|
|
|
|
|
|
|
|
EXT_PROPS.forEach(function(f) {
|
2019-11-27 09:47:16 +00:00
|
|
|
|
var xml = (data.match(matchtag(f[0]))||[])[1];
|
2014-05-16 00:33:34 +00:00
|
|
|
|
switch(f[2]) {
|
2020-04-20 17:17:29 +00:00
|
|
|
|
case "string": if(xml) p[f[1]] = unescapexml(xml); break;
|
2019-11-27 09:47:16 +00:00
|
|
|
|
case "bool": p[f[1]] = xml === "true"; break;
|
2014-05-16 00:33:34 +00:00
|
|
|
|
case "raw":
|
2017-07-05 22:27:54 +00:00
|
|
|
|
var cur = data.match(new RegExp("<" + f[0] + "[^>]*>([\\s\\S]*?)<\/" + f[0] + ">"));
|
2014-05-16 00:33:34 +00:00
|
|
|
|
if(cur && cur.length > 0) q[f[1]] = cur[1];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-05-05 06:34:37 +00:00
|
|
|
|
if(q.HeadingPairs && q.TitlesOfParts) load_props_pairs(q.HeadingPairs, q.TitlesOfParts, p, opts);
|
2017-03-31 18:46:42 +00:00
|
|
|
|
|
2014-05-16 00:33:34 +00:00
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var EXT_PROPS_XML_ROOT = writextag('Properties', null, {
|
|
|
|
|
'xmlns': XMLNS.EXT_PROPS,
|
|
|
|
|
'xmlns:vt': XMLNS.vt
|
|
|
|
|
});
|
|
|
|
|
|
2018-01-23 09:07:51 +00:00
|
|
|
|
function write_ext_props(cp/*::, opts*/)/*:string*/ {
|
|
|
|
|
var o/*:Array<string>*/ = [], W = writextag;
|
2014-05-22 12:16:51 +00:00
|
|
|
|
if(!cp) cp = {};
|
|
|
|
|
cp.Application = "SheetJS";
|
2014-06-29 18:29:45 +00:00
|
|
|
|
o[o.length] = (XML_HEADER);
|
|
|
|
|
o[o.length] = (EXT_PROPS_XML_ROOT);
|
2014-05-16 00:33:34 +00:00
|
|
|
|
|
|
|
|
|
EXT_PROPS.forEach(function(f) {
|
2014-07-28 13:22:32 +00:00
|
|
|
|
if(cp[f[1]] === undefined) return;
|
2014-05-16 00:33:34 +00:00
|
|
|
|
var v;
|
|
|
|
|
switch(f[2]) {
|
2019-11-27 09:47:16 +00:00
|
|
|
|
case 'string': v = escapexml(String(cp[f[1]])); break;
|
2014-05-16 00:33:34 +00:00
|
|
|
|
case 'bool': v = cp[f[1]] ? 'true' : 'false'; break;
|
|
|
|
|
}
|
2014-07-28 13:22:32 +00:00
|
|
|
|
if(v !== undefined) o[o.length] = (W(f[0], v));
|
2014-05-16 00:33:34 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/* TODO: HeadingPairs, TitlesOfParts */
|
2014-06-29 18:29:45 +00:00
|
|
|
|
o[o.length] = (W('HeadingPairs', W('vt:vector', W('vt:variant', '<vt:lpstr>Worksheets</vt:lpstr>')+W('vt:variant', W('vt:i4', String(cp.Worksheets))), {size:2, baseType:"variant"})));
|
2017-03-13 06:46:37 +00:00
|
|
|
|
o[o.length] = (W('TitlesOfParts', W('vt:vector', cp.SheetNames.map(function(s) { return "<vt:lpstr>" + escapexml(s) + "</vt:lpstr>"; }).join(""), {size: cp.Worksheets, baseType:"lpstr"})));
|
2014-06-29 18:29:45 +00:00
|
|
|
|
if(o.length>2){ o[o.length] = ('</Properties>'); o[1]=o[1].replace("/>",">"); }
|
2014-05-16 00:33:34 +00:00
|
|
|
|
return o.join("");
|
|
|
|
|
}
|