diff --git a/README.md b/README.md index 358f542..d01742e 100644 --- a/README.md +++ b/README.md @@ -426,8 +426,14 @@ Special worksheet keys (accessible as `worksheet[key]`, each starting with `!`): `wb.Sheets[sheetname]` returns an object representing the worksheet. -`wb.Props` is an object storing the standard properties. `wb.Custprops` stores -custom properties. Since the XLS standard properties deviate from the XLSX +`wb.Props` is an object storing the standard properties. The following properties are written but not parsed: + - `title` + - `subject` + - `description` + - `keywords` + - `creator` + +`wb.Custprops` stores custom properties. Since the XLS standard properties deviate from the XLSX standard, XLS parsing stores core properties in both places. . diff --git a/bits/33_coreprops.js b/bits/33_coreprops.js index 27d432f..6ea7d82 100644 --- a/bits/33_coreprops.js +++ b/bits/33_coreprops.js @@ -60,13 +60,20 @@ function cp_doit(f, g, h, o, p) { function write_core_props(cp, opts) { var o = [XML_HEADER, CORE_PROPS_XML_ROOT], p = {}; - if(!cp) return o.join(""); + if (opts && opts.Props) { + if (opts.Props.title) o[o.length] = '' + opts.Props.title + ''; + if (opts.Props.subject) o[o.length] = '' + opts.Props.subject + ''; + if (opts.Props.creator) o[o.length] = '' + opts.Props.creator + ''; + if (opts.Props.keywords) o[o.length] = '' + opts.Props.keywords + ''; + if (opts.Props.description) o[o.length] = '' + opts.Props.description + ''; + } + if(cp) { + if(cp.CreatedDate != null) cp_doit("dcterms:created", typeof cp.CreatedDate === "string" ? cp.CreatedDate : write_w3cdtf(cp.CreatedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p); + if(cp.ModifiedDate != null) cp_doit("dcterms:modified", typeof cp.ModifiedDate === "string" ? cp.ModifiedDate : write_w3cdtf(cp.ModifiedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p); - if(cp.CreatedDate != null) cp_doit("dcterms:created", typeof cp.CreatedDate === "string" ? cp.CreatedDate : write_w3cdtf(cp.CreatedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p); - if(cp.ModifiedDate != null) cp_doit("dcterms:modified", typeof cp.ModifiedDate === "string" ? cp.ModifiedDate : write_w3cdtf(cp.ModifiedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p); - - for(var i = 0; i != CORE_PROPS.length; ++i) { var f = CORE_PROPS[i]; cp_doit(f[0], cp[f[1]], null, o, p); } - if(o.length>2){ o[o.length] = (''); o[1]=o[1].replace("/>",">"); } - return o.join(""); + for(var i = 0; i != CORE_PROPS.length; ++i) { var f = CORE_PROPS[i]; cp_doit(f[0], cp[f[1]], null, o, p); } + } + if(o.length>2){ o[o.length] = (''); o[1]=o[1].replace("/>",">"); } + return o.join(""); } diff --git a/xlsx.js b/xlsx.js index e598122..8168609 100644 --- a/xlsx.js +++ b/xlsx.js @@ -2602,15 +2602,22 @@ function cp_doit(f, g, h, o, p) { function write_core_props(cp, opts) { var o = [XML_HEADER, CORE_PROPS_XML_ROOT], p = {}; - if(!cp) return o.join(""); + if (opts && opts.Props) { + if (opts.Props.title) o[o.length] = '' + opts.Props.title + ''; + if (opts.Props.subject) o[o.length] = '' + opts.Props.subject + ''; + if (opts.Props.creator) o[o.length] = '' + opts.Props.creator + ''; + if (opts.Props.keywords) o[o.length] = '' + opts.Props.keywords + ''; + if (opts.Props.description) o[o.length] = '' + opts.Props.description + ''; + } + if(cp) { + if(cp.CreatedDate != null) cp_doit("dcterms:created", typeof cp.CreatedDate === "string" ? cp.CreatedDate : write_w3cdtf(cp.CreatedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p); + if(cp.ModifiedDate != null) cp_doit("dcterms:modified", typeof cp.ModifiedDate === "string" ? cp.ModifiedDate : write_w3cdtf(cp.ModifiedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p); - if(cp.CreatedDate != null) cp_doit("dcterms:created", typeof cp.CreatedDate === "string" ? cp.CreatedDate : write_w3cdtf(cp.CreatedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p); - if(cp.ModifiedDate != null) cp_doit("dcterms:modified", typeof cp.ModifiedDate === "string" ? cp.ModifiedDate : write_w3cdtf(cp.ModifiedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p); - - for(var i = 0; i != CORE_PROPS.length; ++i) { var f = CORE_PROPS[i]; cp_doit(f[0], cp[f[1]], null, o, p); } - if(o.length>2){ o[o.length] = (''); o[1]=o[1].replace("/>",">"); } - return o.join(""); + for(var i = 0; i != CORE_PROPS.length; ++i) { var f = CORE_PROPS[i]; cp_doit(f[0], cp[f[1]], null, o, p); } + } + if(o.length>2){ o[o.length] = (''); o[1]=o[1].replace("/>",">"); } + return o.join(""); } /* 15.2.12.3 Extended File Properties Part */ /* [MS-OSHARED] 2.3.3.2.[1-2].1 (PIDSI/PIDDSI) */