forked from sheetjs/sheetjs
SheetJS
ab2ecebac9
- basic support for parsing BIFF2-4 - basic support for writing BIFF2 - cleaned up some bad substr uses for IE6 compatibility - added flow type annotations for xlsx.flow.js - added numerous null guards (fixes #255 h/t @martinheidegger) - README cleanup (fixes #539 h/t @oliversalzburg) - pin jszip to local version (closes #408 h/t @limouri) bower issues: | id | author | comment | |-----:|:------------------|:------------------------------------------| | #254 | @kkirsche | fixes #254 by removing version from json | | #165 | @vincentcialdella | fixes #165 by changing default script | | #180 | @owencraig | fixes #180 by using xlsx.core.min.js | format issues: | id | author | comment | |-----:|:------------------|:------------------------------------------| | #271 | @morstaine | fixes #271 by reworking related parse fns | | #504 | @JanSchuermannPH | fixes #504 detect FullPaths h/t @Mithgol | | #508 | @basma-emad | fixes #508 offending file used `x:` NS |
77 lines
2.7 KiB
JavaScript
77 lines
2.7 KiB
JavaScript
/* 15.2.12.3 Extended File Properties Part */
|
|
/* [MS-OSHARED] 2.3.3.2.[1-2].1 (PIDSI/PIDDSI) */
|
|
var EXT_PROPS/*:Array<Array<string> >*/ = [
|
|
["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"],
|
|
["TitlesOfParts", "TitlesOfParts", "raw"]
|
|
];
|
|
|
|
XMLNS.EXT_PROPS = "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties";
|
|
RELS.EXT_PROPS = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties';
|
|
|
|
function parse_ext_props(data, p) {
|
|
var q = {}; if(!p) p = {};
|
|
|
|
EXT_PROPS.forEach(function(f) {
|
|
switch(f[2]) {
|
|
case "string": p[f[1]] = (data.match(matchtag(f[0]))||[])[1]; break;
|
|
case "bool": p[f[1]] = (data.match(matchtag(f[0]))||[])[1] === "true"; break;
|
|
case "raw":
|
|
var cur = data.match(new RegExp("<" + f[0] + "[^>]*>(.*)<\/" + f[0] + ">"));
|
|
if(cur && cur.length > 0) q[f[1]] = cur[1];
|
|
break;
|
|
}
|
|
});
|
|
|
|
if(q.HeadingPairs && q.TitlesOfParts) {
|
|
var v = parseVector(q.HeadingPairs);
|
|
var j = 0, widx = 0;
|
|
for(var i = 0; i !== v.length; ++i) {
|
|
switch(v[i].v) {
|
|
case "Worksheets": widx = j; p.Worksheets = +(v[++i].v); break;
|
|
case "Named Ranges": ++i; break; // TODO: Handle Named Ranges
|
|
}
|
|
}
|
|
var parts = parseVector(q.TitlesOfParts).map(function(x) { return utf8read(x.v); });
|
|
p.SheetNames = parts.slice(widx, widx + p.Worksheets);
|
|
}
|
|
return p;
|
|
}
|
|
|
|
var EXT_PROPS_XML_ROOT = writextag('Properties', null, {
|
|
'xmlns': XMLNS.EXT_PROPS,
|
|
'xmlns:vt': XMLNS.vt
|
|
});
|
|
|
|
function write_ext_props(cp, opts)/*:string*/ {
|
|
var o = [], p = {}, W = writextag;
|
|
if(!cp) cp = {};
|
|
cp.Application = "SheetJS";
|
|
o[o.length] = (XML_HEADER);
|
|
o[o.length] = (EXT_PROPS_XML_ROOT);
|
|
|
|
EXT_PROPS.forEach(function(f) {
|
|
if(cp[f[1]] === undefined) return;
|
|
var v;
|
|
switch(f[2]) {
|
|
case 'string': v = cp[f[1]]; break;
|
|
case 'bool': v = cp[f[1]] ? 'true' : 'false'; break;
|
|
}
|
|
if(v !== undefined) o[o.length] = (W(f[0], v));
|
|
});
|
|
|
|
/* TODO: HeadingPairs, TitlesOfParts */
|
|
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"})));
|
|
o[o.length] = (W('TitlesOfParts', W('vt:vector', cp.SheetNames.map(function(s) { return "<vt:lpstr>" + s + "</vt:lpstr>"; }).join(""), {size: cp.Worksheets, baseType:"lpstr"})));
|
|
if(o.length>2){ o[o.length] = ('</Properties>'); o[1]=o[1].replace("/>",">"); }
|
|
return o.join("");
|
|
}
|