xsheetjs/bits/36_xlsprops.js
SheetJS 0a57229d3b version bump 0.15.6: niggles from 2012
- CFB prevent infinite loop (h/t @rossj)
- pass updated eslint checks (fixes #1726 h/t @BjoernRave)
- defined name proper encoding (fixes #1785 h/t @laohe98)
- correct theme color order (fixes #389 h/t @foreverpw)
- ODS / XLML more aggressive flagging of stub cells
- cellStyles implies sheetStubs
- updated SSF to 0.10.3
2020-03-15 03:57:44 -04:00

92 lines
3.2 KiB
JavaScript

/* Common Name -> XLML Name */
var XLMLDocPropsMap = {
Title: 'Title',
Subject: 'Subject',
Author: 'Author',
Keywords: 'Keywords',
Comments: 'Description',
LastAuthor: 'LastAuthor',
RevNumber: 'Revision',
Application: 'AppName',
/* TotalTime: 'TotalTime', */
LastPrinted: 'LastPrinted',
CreatedDate: 'Created',
ModifiedDate: 'LastSaved',
/* Pages */
/* Words */
/* Characters */
Category: 'Category',
/* PresentationFormat */
Manager: 'Manager',
Company: 'Company',
/* Guid */
/* HyperlinkBase */
/* Bytes */
/* Lines */
/* Paragraphs */
/* CharactersWithSpaces */
AppVersion: 'Version',
ContentStatus: 'ContentStatus', /* NOTE: missing from schema */
Identifier: 'Identifier', /* NOTE: missing from schema */
Language: 'Language' /* NOTE: missing from schema */
};
var evert_XLMLDPM = evert(XLMLDocPropsMap);
function xlml_set_prop(Props, tag/*:string*/, val) {
tag = evert_XLMLDPM[tag] || tag;
Props[tag] = val;
}
function xlml_write_docprops(Props, opts) {
var o/*:Array<string>*/ = [];
keys(XLMLDocPropsMap).map(function(m) {
for(var i = 0; i < CORE_PROPS.length; ++i) if(CORE_PROPS[i][1] == m) return CORE_PROPS[i];
for(i = 0; i < EXT_PROPS.length; ++i) if(EXT_PROPS[i][1] == m) return EXT_PROPS[i];
throw m;
}).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]];
switch(p[2]) {
case 'date': m = new Date(m).toISOString().replace(/\.\d*Z/,"Z"); break;
}
if(typeof m == 'number') m = String(m);
else if(m === true || m === false) { m = m ? "1" : "0"; }
else if(m instanceof Date) m = new Date(m).toISOString().replace(/\.\d*Z/,"");
o.push(writetag(XLMLDocPropsMap[p[1]] || p[1], m));
});
return writextag('DocumentProperties', o.join(""), {xmlns:XLMLNS.o });
}
function xlml_write_custprops(Props, Custprops/*::, opts*/) {
var BLACKLIST = ["Worksheets","SheetNames"];
var T = 'CustomDocumentProperties';
var o/*:Array<string>*/ = [];
if(Props) keys(Props).forEach(function(k) {
/*:: if(!Props) return; */
if(!Object.prototype.hasOwnProperty.call(Props, k)) return;
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;
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(!Object.prototype.hasOwnProperty.call(Custprops, k)) return;
if(Props && Object.prototype.hasOwnProperty.call(Props, 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 + '>';
}