Add doc props

This commit is contained in:
Pieter Sheth-Voss 2015-12-04 23:15:03 -05:00
parent 0bf1153da5
commit 7de41c2657
3 changed files with 36 additions and 16 deletions

@ -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. .

@ -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] = '<dc:title>' + opts.Props.title + '</dc:title>';
if (opts.Props.subject) o[o.length] = '<dc:subject>' + opts.Props.subject + '</dc:subject>';
if (opts.Props.creator) o[o.length] = '<dc:creator>' + opts.Props.creator + '</dc:creator>';
if (opts.Props.keywords) o[o.length] = '<cp:keywords>' + opts.Props.keywords + '</cp:keywords>';
if (opts.Props.description) o[o.length] = '<dc:description>' + opts.Props.description + '</dc: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] = ('</cp:coreProperties>'); 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] = ('</cp:coreProperties>'); o[1]=o[1].replace("/>",">"); }
return o.join("");
}

21
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] = '<dc:title>' + opts.Props.title + '</dc:title>';
if (opts.Props.subject) o[o.length] = '<dc:subject>' + opts.Props.subject + '</dc:subject>';
if (opts.Props.creator) o[o.length] = '<dc:creator>' + opts.Props.creator + '</dc:creator>';
if (opts.Props.keywords) o[o.length] = '<cp:keywords>' + opts.Props.keywords + '</cp:keywords>';
if (opts.Props.description) o[o.length] = '<dc:description>' + opts.Props.description + '</dc: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] = ('</cp:coreProperties>'); 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] = ('</cp:coreProperties>'); 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) */