2017-04-10 05:10:54 +00:00
|
|
|
/* Common Name -> XLML Name */
|
|
|
|
var XLMLDocPropsMap = {
|
|
|
|
Category: 'Category',
|
|
|
|
ContentStatus: 'ContentStatus', /* NOTE: missing from schema */
|
|
|
|
Keywords: 'Keywords',
|
|
|
|
LastAuthor: 'LastAuthor',
|
|
|
|
LastPrinted: 'LastPrinted',
|
|
|
|
RevNumber: 'Revision',
|
|
|
|
Author: 'Author',
|
|
|
|
Comments: 'Description',
|
|
|
|
Identifier: 'Identifier', /* NOTE: missing from schema */
|
|
|
|
Language: 'Language', /* NOTE: missing from schema */
|
|
|
|
Subject: 'Subject',
|
|
|
|
Title: 'Title',
|
|
|
|
CreatedDate: 'Created',
|
|
|
|
ModifiedDate: 'LastSaved',
|
|
|
|
|
|
|
|
Application: 'AppName',
|
|
|
|
AppVersion: 'Version',
|
|
|
|
TotalTime: 'TotalTime',
|
|
|
|
Manager: 'Manager',
|
|
|
|
Company: 'Company'
|
|
|
|
};
|
|
|
|
var evert_XLMLDPM = evert(XLMLDocPropsMap);
|
|
|
|
|
2017-02-10 19:23:01 +00:00
|
|
|
function xlml_set_prop(Props, tag/*:string*/, val) {
|
2017-04-10 05:10:54 +00:00
|
|
|
tag = evert_XLMLDPM[tag] || tag;
|
2015-04-02 20:32:22 +00:00
|
|
|
Props[tag] = val;
|
|
|
|
}
|
|
|
|
|
2017-03-14 08:19:51 +00:00
|
|
|
|
|
|
|
/* TODO: verify */
|
2017-04-10 05:10:54 +00:00
|
|
|
function xlml_write_docprops(Props, opts) {
|
2017-03-14 08:19:51 +00:00
|
|
|
var o = [];
|
2017-04-10 05:10:54 +00:00
|
|
|
CORE_PROPS.concat(EXT_PROPS).forEach(function(p) {
|
|
|
|
if(Props[p[1]] == null) return;
|
|
|
|
var m = opts && opts.Props && opts.Props[p[1]] != null ? opts.Props[p[1]] : Props[p[1]];
|
2017-03-14 08:19:51 +00:00
|
|
|
switch(p[2]) {
|
|
|
|
case 'date': m = new Date(m).toISOString(); break;
|
|
|
|
}
|
2017-04-10 05:10:54 +00:00
|
|
|
if(typeof m == 'number') m = String(m);
|
|
|
|
else if(m === true || m === false) { t = "boolean"; m = m ? "1" : "0"; }
|
|
|
|
else if(m instanceof Date) m = new Date(m).toISOString();
|
|
|
|
o.push(writetag(XLMLDocPropsMap[p[1]] || p[1], m));
|
2017-03-14 08:19:51 +00:00
|
|
|
});
|
2017-04-10 05:10:54 +00:00
|
|
|
return writextag('DocumentProperties', o.join(""), {xmlns:XLMLNS.o });
|
2017-03-14 08:19:51 +00:00
|
|
|
}
|
2017-04-10 05:10:54 +00:00
|
|
|
function xlml_write_custprops(Props, Custprops, opts) {
|
|
|
|
var BLACKLIST = ["Worksheets","SheetNames"];
|
2017-03-14 08:19:51 +00:00
|
|
|
var T = 'CustomDocumentProperties';
|
|
|
|
var o = [];
|
|
|
|
if(Props) keys(Props).forEach(function(k) {
|
|
|
|
/*:: if(!Props) return; */
|
|
|
|
if(!Props.hasOwnProperty(k)) return;
|
2017-04-10 05:10:54 +00:00
|
|
|
for(var i = 0; i < CORE_PROPS.length; ++i) if(k == CORE_PROPS[i][1]) return;
|
|
|
|
for(i = 0; i < EXT_PROPS.length; ++i) if(k == EXT_PROPS[i][1]) return;
|
|
|
|
for(i = 0; i < BLACKLIST.length; ++i) if(k == BLACKLIST[i]) return;
|
|
|
|
|
2017-03-14 08:19:51 +00:00
|
|
|
var m = Props[k];
|
|
|
|
var t = "string";
|
|
|
|
if(typeof m == 'number') { t = "float"; m = String(m); }
|
|
|
|
else if(m === true || m === false) { t = "boolean"; m = m ? "1" : "0"; }
|
|
|
|
else m = String(m);
|
|
|
|
o.push(writextag(escapexmltag(k), m, {"dt:dt":t}));
|
|
|
|
});
|
|
|
|
if(Custprops) keys(Custprops).forEach(function(k) {
|
|
|
|
/*:: if(!Custprops) return; */
|
|
|
|
if(!Custprops.hasOwnProperty(k)) return;
|
|
|
|
var m = Custprops[k];
|
|
|
|
var t = "string";
|
|
|
|
if(typeof m == 'number') { t = "float"; m = String(m); }
|
|
|
|
else if(m === true || m === false) { t = "boolean"; m = m ? "1" : "0"; }
|
|
|
|
else if(m instanceof Date) { t = "dateTime.tz"; m = m.toISOString(); }
|
|
|
|
else m = String(m);
|
|
|
|
o.push(writextag(escapexmltag(k), m, {"dt:dt":t}));
|
|
|
|
});
|
|
|
|
return '<' + T + ' xmlns="' + XLMLNS.o + '">' + o.join("") + '</' + T + '>';
|
|
|
|
}
|