2014-04-03 22:51:54 +00:00
|
|
|
/* Parts enumerated in OPC spec, MS-XLSB and MS-XLSX */
|
|
|
|
/* 12.3 Part Summary <SpreadsheetML> */
|
|
|
|
/* 14.2 Part Summary <DrawingML> */
|
|
|
|
/* [MS-XLSX] 2.1 Part Enumerations */
|
|
|
|
/* [MS-XLSB] 2.1.7 Part Enumeration */
|
2014-01-28 16:38:02 +00:00
|
|
|
var ct2type = {
|
2014-04-03 22:51:54 +00:00
|
|
|
/* Workbook */
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml": "workbooks",
|
|
|
|
|
|
|
|
/* Worksheet */
|
|
|
|
"application/vnd.ms-excel.binIndexWs": "TODO", /* Binary Index */
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2014-04-03 22:51:54 +00:00
|
|
|
/* Chartsheet */
|
|
|
|
"application/vnd.ms-excel.chartsheet": "TODO",
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.chartsheet+xml": "TODO",
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2014-04-03 22:51:54 +00:00
|
|
|
/* Dialogsheet */
|
|
|
|
"application/vnd.ms-excel.dialogsheet": "TODO",
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.dialogsheet+xml": "TODO",
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2014-04-03 22:51:54 +00:00
|
|
|
/* Macrosheet */
|
|
|
|
"application/vnd.ms-excel.macrosheet": "TODO",
|
|
|
|
"application/vnd.ms-excel.macrosheet+xml": "TODO",
|
|
|
|
"application/vnd.ms-excel.intlmacrosheet": "TODO",
|
|
|
|
"application/vnd.ms-excel.binIndexMs": "TODO", /* Binary Index */
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2014-04-03 22:51:54 +00:00
|
|
|
/* File Properties */
|
2014-01-28 16:38:02 +00:00
|
|
|
"application/vnd.openxmlformats-package.core-properties+xml": "coreprops",
|
2014-02-14 03:39:03 +00:00
|
|
|
"application/vnd.openxmlformats-officedocument.custom-properties+xml": "custprops",
|
2014-04-03 22:51:54 +00:00
|
|
|
"application/vnd.openxmlformats-officedocument.extended-properties+xml": "extprops",
|
|
|
|
|
|
|
|
/* Custom Data Properties */
|
|
|
|
"application/vnd.openxmlformats-officedocument.customXmlProperties+xml": "TODO",
|
|
|
|
|
|
|
|
/* Comments */
|
|
|
|
"application/vnd.ms-excel.comments": "comments",
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml": "comments",
|
|
|
|
|
|
|
|
/* PivotTable */
|
|
|
|
"application/vnd.ms-excel.pivotTable": "TODO",
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml": "TODO",
|
|
|
|
|
|
|
|
/* Calculation Chain */
|
|
|
|
"application/vnd.ms-excel.calcChain": "calcchains",
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.calcChain+xml": "calcchains",
|
|
|
|
|
|
|
|
/* Printer Settings */
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings": "TODO",
|
|
|
|
|
|
|
|
/* ActiveX */
|
|
|
|
"application/vnd.ms-office.activeX": "TODO",
|
|
|
|
"application/vnd.ms-office.activeX+xml": "TODO",
|
|
|
|
|
|
|
|
/* Custom Toolbars */
|
|
|
|
"application/vnd.ms-excel.attachedToolbars": "TODO",
|
|
|
|
|
|
|
|
/* External Data Connections */
|
|
|
|
"application/vnd.ms-excel.connections": "TODO",
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.connections+xml": "TODO",
|
|
|
|
|
|
|
|
/* External Links */
|
|
|
|
"application/vnd.ms-excel.externalLink": "TODO",
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml": "TODO",
|
|
|
|
|
|
|
|
/* Metadata */
|
|
|
|
"application/vnd.ms-excel.sheetMetadata": "TODO",
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheetMetadata+xml": "TODO",
|
|
|
|
|
|
|
|
/* PivotCache */
|
|
|
|
"application/vnd.ms-excel.pivotCacheDefinition": "TODO",
|
|
|
|
"application/vnd.ms-excel.pivotCacheRecords": "TODO",
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml": "TODO",
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml": "TODO",
|
|
|
|
|
|
|
|
/* Query Table */
|
|
|
|
"application/vnd.ms-excel.queryTable": "TODO",
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.queryTable+xml": "TODO",
|
|
|
|
|
|
|
|
/* Shared Workbook */
|
|
|
|
"application/vnd.ms-excel.userNames": "TODO",
|
|
|
|
"application/vnd.ms-excel.revisionHeaders": "TODO",
|
|
|
|
"application/vnd.ms-excel.revisionLog": "TODO",
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.revisionHeaders+xml": "TODO",
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.revisionLog+xml": "TODO",
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.userNames+xml": "TODO",
|
|
|
|
|
|
|
|
/* Single Cell Table */
|
|
|
|
"application/vnd.ms-excel.tableSingleCells": "TODO",
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.tableSingleCells+xml": "TODO",
|
|
|
|
|
|
|
|
/* Slicer */
|
|
|
|
"application/vnd.ms-excel.slicer": "TODO",
|
|
|
|
"application/vnd.ms-excel.slicerCache": "TODO",
|
|
|
|
"application/vnd.ms-excel.slicer+xml": "TODO",
|
|
|
|
"application/vnd.ms-excel.slicerCache+xml": "TODO",
|
|
|
|
|
|
|
|
/* Sort Map */
|
|
|
|
"application/vnd.ms-excel.wsSortMap": "TODO",
|
|
|
|
|
|
|
|
/* Table */
|
|
|
|
"application/vnd.ms-excel.table": "TODO",
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml": "TODO",
|
|
|
|
|
|
|
|
/* Themes */
|
|
|
|
"application/vnd.openxmlformats-officedocument.theme+xml": "themes",
|
|
|
|
|
|
|
|
/* Timeline */
|
|
|
|
"application/vnd.ms-excel.Timeline+xml": "TODO", /* verify */
|
|
|
|
"application/vnd.ms-excel.TimelineCache+xml": "TODO", /* verify */
|
|
|
|
|
|
|
|
/* VBA */
|
|
|
|
"application/vnd.ms-office.vbaProject": "vba",
|
|
|
|
"application/vnd.ms-office.vbaProjectSignature": "vba",
|
|
|
|
|
|
|
|
/* Volatile Dependencies */
|
|
|
|
"application/vnd.ms-office.volatileDependencies": "TODO",
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.volatileDependencies+xml": "TODO",
|
|
|
|
|
|
|
|
/* Control Properties */
|
|
|
|
"application/vnd.ms-excel.controlproperties+xml": "TODO",
|
|
|
|
|
|
|
|
/* Data Model */
|
|
|
|
"application/vnd.openxmlformats-officedocument.model+data": "TODO",
|
|
|
|
|
|
|
|
/* Survey */
|
|
|
|
"application/vnd.ms-excel.Survey+xml": "TODO",
|
|
|
|
|
|
|
|
/* Drawing */
|
|
|
|
"application/vnd.openxmlformats-officedocument.drawing+xml": "TODO",
|
|
|
|
"application/vnd.openxmlformats-officedocument.drawingml.chart+xml": "TODO",
|
|
|
|
"application/vnd.openxmlformats-officedocument.drawingml.chartshapes+xml": "TODO",
|
|
|
|
"application/vnd.openxmlformats-officedocument.drawingml.diagramColors+xml": "TODO",
|
|
|
|
"application/vnd.openxmlformats-officedocument.drawingml.diagramData+xml": "TODO",
|
|
|
|
"application/vnd.openxmlformats-officedocument.drawingml.diagramLayout+xml": "TODO",
|
|
|
|
"application/vnd.openxmlformats-officedocument.drawingml.diagramStyle+xml": "TODO",
|
|
|
|
|
|
|
|
/* VML */
|
|
|
|
"application/vnd.openxmlformats-officedocument.vmlDrawing": "TODO",
|
|
|
|
|
2014-05-16 00:33:34 +00:00
|
|
|
"application/vnd.openxmlformats-package.relationships+xml": "rels",
|
2014-04-03 22:51:54 +00:00
|
|
|
"application/vnd.openxmlformats-officedocument.oleObject": "TODO",
|
|
|
|
|
2014-05-16 00:33:34 +00:00
|
|
|
"sheet": "js"
|
2014-01-28 16:38:02 +00:00
|
|
|
};
|
|
|
|
|
2014-05-16 00:33:34 +00:00
|
|
|
var CT_LIST = (function(){
|
|
|
|
var o = {
|
|
|
|
workbooks: {
|
|
|
|
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",
|
|
|
|
xlsm: "application/vnd.ms-excel.sheet.macroEnabled.main+xml",
|
|
|
|
xlsb: "application/vnd.ms-excel.sheet.binary.macroEnabled.main",
|
|
|
|
xltx: "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml"
|
|
|
|
},
|
|
|
|
strs: { /* Shared Strings */
|
|
|
|
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",
|
|
|
|
xlsb: "application/vnd.ms-excel.sharedStrings"
|
|
|
|
},
|
|
|
|
sheets: {
|
|
|
|
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",
|
|
|
|
xlsb: "application/vnd.ms-excel.worksheet"
|
|
|
|
},
|
|
|
|
styles: {/* Styles */
|
|
|
|
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",
|
|
|
|
xlsb: "application/vnd.ms-excel.styles"
|
2014-01-28 16:38:02 +00:00
|
|
|
}
|
2014-05-16 00:33:34 +00:00
|
|
|
};
|
|
|
|
keys(o).forEach(function(k) { if(!o[k].xlsm) o[k].xlsm = o[k].xlsx; });
|
|
|
|
keys(o).forEach(function(k){ keys(o[k]).forEach(function(v) { ct2type[o[k][v]] = k; }); });
|
|
|
|
return o;
|
|
|
|
})();
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2014-05-16 00:33:34 +00:00
|
|
|
var type2ct = evert(ct2type, true);
|
2014-02-14 03:39:03 +00:00
|
|
|
|
2014-05-16 00:33:34 +00:00
|
|
|
XMLNS.CT = 'http://schemas.openxmlformats.org/package/2006/content-types';
|
|
|
|
|
|
|
|
function parse_ct(data, opts) {
|
|
|
|
var ctext = {};
|
2014-01-28 16:38:02 +00:00
|
|
|
if(!data || !data.match) return data;
|
|
|
|
var ct = { workbooks: [], sheets: [], calcchains: [], themes: [], styles: [],
|
2014-04-03 22:51:54 +00:00
|
|
|
coreprops: [], extprops: [], custprops: [], strs:[], comments: [], vba: [],
|
2014-05-16 00:33:34 +00:00
|
|
|
TODO:[], rels:[], xmlns: "" };
|
2014-01-28 16:38:02 +00:00
|
|
|
(data.match(/<[^>]*>/g)||[]).forEach(function(x) {
|
|
|
|
var y = parsexmltag(x);
|
|
|
|
switch(y[0]) {
|
|
|
|
case '<?xml': break;
|
|
|
|
case '<Types': ct.xmlns = y.xmlns; break;
|
|
|
|
case '<Default': ctext[y.Extension] = y.ContentType; break;
|
|
|
|
case '<Override':
|
|
|
|
if(y.ContentType in ct2type)ct[ct2type[y.ContentType]].push(y.PartName);
|
2014-05-16 00:33:34 +00:00
|
|
|
else if(opts.WTF) console.error(y);
|
2014-01-28 16:38:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2014-05-16 00:33:34 +00:00
|
|
|
if(ct.xmlns !== XMLNS.CT) throw new Error("Unknown Namespace: " + ct.xmlns);
|
2014-01-28 16:38:02 +00:00
|
|
|
ct.calcchain = ct.calcchains.length > 0 ? ct.calcchains[0] : "";
|
|
|
|
ct.sst = ct.strs.length > 0 ? ct.strs[0] : "";
|
|
|
|
ct.style = ct.styles.length > 0 ? ct.styles[0] : "";
|
2014-04-03 22:51:54 +00:00
|
|
|
ct.defaults = ctext;
|
2014-01-28 16:38:02 +00:00
|
|
|
delete ct.calcchains;
|
|
|
|
return ct;
|
|
|
|
}
|
|
|
|
|
2014-05-16 00:33:34 +00:00
|
|
|
var CTYPE_XML_ROOT = writextag('Types', null, {
|
|
|
|
'xmlns': XMLNS.CT,
|
|
|
|
'xmlns:xsd': XMLNS.xsd,
|
|
|
|
'xmlns:xsi': XMLNS.xsi
|
|
|
|
});
|
|
|
|
|
|
|
|
var CTYPE_DEFAULTS = [
|
|
|
|
['xml', 'application/xml'],
|
|
|
|
['rels', type2ct.rels[0]]
|
|
|
|
].map(function(x) {
|
|
|
|
return writextag('Default', null, {'Extension':x[0], 'ContentType': x[1]});
|
|
|
|
});
|
|
|
|
|
|
|
|
function write_ct(ct, opts) {
|
|
|
|
var o = [], v;
|
|
|
|
o.push(XML_HEADER);
|
|
|
|
o.push(CTYPE_XML_ROOT);
|
|
|
|
o = o.concat(CTYPE_DEFAULTS);
|
|
|
|
var f1 = function(w) {
|
|
|
|
if(ct[w] && ct[w].length > 0) {
|
|
|
|
v = ct[w][0];
|
|
|
|
o.push(writextag('Override', null, {
|
|
|
|
'PartName': (v[0] == '/' ? "":"/") + v,
|
|
|
|
'ContentType': CT_LIST[w][opts.bookType || 'xlsx']
|
|
|
|
}));
|
2014-01-28 16:38:02 +00:00
|
|
|
}
|
2014-01-29 06:00:09 +00:00
|
|
|
};
|
2014-05-16 00:33:34 +00:00
|
|
|
var f2 = function(w) {
|
|
|
|
ct[w].forEach(function(v) {
|
|
|
|
o.push(writextag('Override', null, {
|
|
|
|
'PartName': (v[0] == '/' ? "":"/") + v,
|
|
|
|
'ContentType': CT_LIST[w][opts.bookType || 'xlsx']
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
var f3 = function(t) {
|
|
|
|
(ct[t]||[]).forEach(function(v) {
|
|
|
|
o.push(writextag('Override', null, {
|
|
|
|
'PartName': (v[0] == '/' ? "":"/") + v,
|
|
|
|
'ContentType': type2ct[t][0]
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
f1('workbooks');
|
|
|
|
f2('sheets');
|
|
|
|
f3('themes');
|
|
|
|
['strs', 'styles'].forEach(f1);
|
|
|
|
['coreprops', 'extprops', 'custprops'].forEach(f3);
|
|
|
|
if(o.length>2){ o.push('</Types>'); o[1]=o[1].replace("/>",">"); }
|
|
|
|
return o.join("");
|
2014-01-28 16:38:02 +00:00
|
|
|
}
|