2017-03-27 21:35:15 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								/* 9.3 Relationships */
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-10 19:23:01 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								var RELS = ({
							 | 
						
					
						
							
								
									
										
										
										
											2014-05-16 00:33:34 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									WB: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-28 04:41:01 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									SHEET: "http://sheetjs.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-31 00:47:35 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									HLINK: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-02 06:47:25 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									VML: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing",
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-01 03:09:14 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									XPATH: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/externalLinkPath",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									XMISS: "http://schemas.microsoft.com/office/2006/relationships/xlExternalLinkPath/xlPathMissing",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									XLINK: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/externalLink",
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-11 08:38:33 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									CXML: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									CXMLP: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXmlProps",
							 | 
						
					
						
							
								
									
										
										
										
											2022-03-14 06:51:33 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									CMNT: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									CORE_PROPS: "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									EXT_PROPS: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties',
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									CUST_PROPS: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties',
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									SST: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									STY: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									THEME: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									CHART: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",
							 | 
						
					
						
							
								
									
										
										
										
											2022-03-16 03:18:09 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									CHARTEX: "http://schemas.microsoft.com/office/2014/relationships/chartEx",
							 | 
						
					
						
							
								
									
										
										
										
											2022-03-14 06:51:33 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									CS: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartsheet",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									WS: [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										"http://purl.oclc.org/ooxml/officeDocument/relationships/worksheet"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									DS: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/dialogsheet",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									MS: "http://schemas.microsoft.com/office/2006/relationships/xlMacrosheet",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									IMG: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									DRAW: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									XLMETA: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sheetMetadata",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									TCMNT: "http://schemas.microsoft.com/office/2017/10/relationships/threadedComment",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									PEOPLE: "http://schemas.microsoft.com/office/2017/10/relationships/person",
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-28 04:41:01 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									VBA: "http://schemas.microsoft.com/office/2006/relationships/vbaProject"
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-10 19:23:01 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}/*:any*/);
							 | 
						
					
						
							
								
									
										
										
										
											2014-05-16 00:33:34 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2022-03-14 06:51:33 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-27 21:35:15 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								/* 9.3.3 Representing Relationships */
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								function get_rels_path(file/*:string*/)/*:string*/ {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									var n = file.lastIndexOf("/");
							 | 
						
					
						
							
								
									
										
										
										
											2018-01-11 08:01:25 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									return file.slice(0,n+1) + '_rels/' + file.slice(n+1) + ".rels";
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-27 21:35:15 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-10 19:23:01 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								function parse_rels(data/*:?string*/, currentFilePath/*:string*/) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-15 01:46:49 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									var rels = {"!id":{}};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									if (!data) return rels;
							 | 
						
					
						
							
								
									
										
										
										
											2014-05-16 00:33:34 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									if (currentFilePath.charAt(0) !== '/') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										currentFilePath = '/'+currentFilePath;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									var hash = {};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-10 19:23:01 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									(data.match(tagregex)||[]).forEach(function(x) {
							 | 
						
					
						
							
								
									
										
										
										
											2014-05-16 00:33:34 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										var y = parsexmltag(x);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										/* 9.3.2.2 OPC_Relationships */
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										if (y[0] === '<Relationship') {
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-29 09:16:02 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											var rel = {}; rel.Type = y.Type; rel.Target = y.Target; rel.Id = y.Id; if(y.TargetMode) rel.TargetMode = y.TargetMode;
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-27 21:35:15 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											var canonictarget = y.TargetMode === 'External' ? y.Target : resolve_path(y.Target, currentFilePath);
							 | 
						
					
						
							
								
									
										
										
										
											2014-05-16 00:33:34 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											rels[canonictarget] = rel;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											hash[y.Id] = rel;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									rels["!id"] = hash;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									return rels;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								var RELS_ROOT = writextag('Relationships', null, {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									//'xmlns:ns0': XMLNS.RELS,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									'xmlns': XMLNS.RELS
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								/* TODO */
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-10 19:23:01 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								function write_rels(rels)/*:string*/ {
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-08 06:55:35 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									var o = [XML_HEADER, RELS_ROOT];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									keys(rels['!id']).forEach(function(rid) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										o[o.length] = (writextag('Relationship', null, rels['!id'][rid]));
							 | 
						
					
						
							
								
									
										
										
										
											2014-05-16 00:33:34 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									});
							 | 
						
					
						
							
								
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									if(o.length>2){ o[o.length] = ('</Relationships>'); o[1]=o[1].replace("/>",">"); }
							 | 
						
					
						
							
								
									
										
										
										
											2014-05-16 00:33:34 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									return o.join("");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-31 00:47:35 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-01 03:09:14 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								var RELS_EXTERN = [RELS.HLINK, RELS.XPATH, RELS.XMISS];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								function add_rels(rels, rId/*:number*/, f, type, relobj, targetmode/*:?string*/)/*:number*/ {
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-31 00:47:35 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									if(!relobj) relobj = {};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									if(!rels['!id']) rels['!id'] = {};
							 | 
						
					
						
							
								
									
										
										
										
											2022-03-01 09:14:41 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									if(!rels['!idx']) rels['!idx'] = 1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									if(rId < 0) for(rId = rels['!idx']; rels['!id']['rId' + rId]; ++rId){/* empty */}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									rels['!idx'] = rId + 1;
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-31 00:47:35 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									relobj.Id = 'rId' + rId;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									relobj.Type = type;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									relobj.Target = f;
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-01 03:09:14 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									if(targetmode) relobj.TargetMode = targetmode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									else if(RELS_EXTERN.indexOf(relobj.Type) > -1) relobj.TargetMode = "External";
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-31 00:47:35 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									if(rels['!id'][relobj.Id]) throw new Error("Cannot rewrite rId " + rId);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									rels['!id'][relobj.Id] = relobj;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									rels[('/' + relobj.Target).replace("//","/")] = relobj;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									return rId;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |