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 |
62 lines
1.8 KiB
JavaScript
62 lines
1.8 KiB
JavaScript
/* 9.3.2 OPC Relationships Markup */
|
|
var RELS = ({
|
|
WB: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
|
|
SHEET: "http://sheetjs.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
|
|
}/*:any*/);
|
|
|
|
function parse_rels(data/*:?string*/, currentFilePath/*:string*/) {
|
|
if (!data) return data;
|
|
if (currentFilePath.charAt(0) !== '/') {
|
|
currentFilePath = '/'+currentFilePath;
|
|
}
|
|
var rels = {};
|
|
var hash = {};
|
|
var resolveRelativePathIntoAbsolute = function (to) {
|
|
var toksFrom = currentFilePath.split('/');
|
|
toksFrom.pop(); // folder path
|
|
var toksTo = to.split('/');
|
|
var reversed = [];
|
|
while (toksTo.length !== 0) {
|
|
var tokTo = toksTo.shift();
|
|
if (tokTo === '..') {
|
|
toksFrom.pop();
|
|
} else if (tokTo !== '.') {
|
|
toksFrom.push(tokTo);
|
|
}
|
|
}
|
|
return toksFrom.join('/');
|
|
};
|
|
|
|
(data.match(tagregex)||[]).forEach(function(x) {
|
|
var y = parsexmltag(x);
|
|
/* 9.3.2.2 OPC_Relationships */
|
|
if (y[0] === '<Relationship') {
|
|
var rel = {}; rel.Type = y.Type; rel.Target = y.Target; rel.Id = y.Id; rel.TargetMode = y.TargetMode;
|
|
var canonictarget = y.TargetMode === 'External' ? y.Target : resolveRelativePathIntoAbsolute(y.Target);
|
|
rels[canonictarget] = rel;
|
|
hash[y.Id] = rel;
|
|
}
|
|
});
|
|
rels["!id"] = hash;
|
|
return rels;
|
|
}
|
|
|
|
XMLNS.RELS = 'http://schemas.openxmlformats.org/package/2006/relationships';
|
|
|
|
var RELS_ROOT = writextag('Relationships', null, {
|
|
//'xmlns:ns0': XMLNS.RELS,
|
|
'xmlns': XMLNS.RELS
|
|
});
|
|
|
|
/* TODO */
|
|
function write_rels(rels)/*:string*/ {
|
|
var o = [];
|
|
o[o.length] = (XML_HEADER);
|
|
o[o.length] = (RELS_ROOT);
|
|
keys(rels['!id']).forEach(function(rid) { var rel = rels['!id'][rid];
|
|
o[o.length] = (writextag('Relationship', null, rel));
|
|
});
|
|
if(o.length>2){ o[o.length] = ('</Relationships>'); o[1]=o[1].replace("/>",">"); }
|
|
return o.join("");
|
|
}
|