From bbeec3edfd351726e6911e66fdb2b05aed54dbfd Mon Sep 17 00:00:00 2001 From: Pieter Sheth-Voss Date: Fri, 4 Dec 2015 21:02:05 -0500 Subject: [PATCH 1/4] Add row/col breaks --- bits/67_wsxml.js | 35 +++++++++++++++++++++++++++++++++++ xlsx.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/bits/67_wsxml.js b/bits/67_wsxml.js index 937a14d..64a057e 100644 --- a/bits/67_wsxml.js +++ b/bits/67_wsxml.js @@ -70,6 +70,17 @@ function write_ws_xml_merges(merges) { return o + ''; } +// +// +// +// +// +// +// + + + + function parse_ws_xml_hlinks(s, data, rels) { for(var i = 0; i != data.length; ++i) { var val = parsexmltag(data[i], true); @@ -313,6 +324,30 @@ function write_ws_xml(idx, opts, wb) { if(ws['!merges'] !== undefined && ws['!merges'].length > 0) o[o.length] = (write_ws_xml_merges(ws['!merges'])); + if (ws['!rowBreaks'] !== undefined) o[o.length] = write_ws_xml_row_breaks(ws['!rowBreaks']) + if (ws['!colBreaks'] !== undefined) o[o.length] = write_ws_xml_col_breaks(ws['!colBreaks']) + if(o.length>2) { o[o.length] = (''); o[1]=o[1].replace("/>",">"); } return o.join(""); } + +function write_ws_xml_row_breaks(breaks) { + console.log("Writing breaks") + var brk = []; + for (var i=0; i'; } +// +// +// +// +// +// +// + + + + function parse_ws_xml_hlinks(s, data, rels) { for(var i = 0; i != data.length; ++i) { var val = parsexmltag(data[i], true); @@ -7838,10 +7849,34 @@ function write_ws_xml(idx, opts, wb) { if(ws['!merges'] !== undefined && ws['!merges'].length > 0) o[o.length] = (write_ws_xml_merges(ws['!merges'])); + if (ws['!rowBreaks'] !== undefined) o[o.length] = write_ws_xml_row_breaks(ws['!rowBreaks']) + if (ws['!colBreaks'] !== undefined) o[o.length] = write_ws_xml_col_breaks(ws['!colBreaks']) + if(o.length>2) { o[o.length] = (''); o[1]=o[1].replace("/>",">"); } return o.join(""); } +function write_ws_xml_row_breaks(breaks) { + console.log("Writing breaks") + var brk = []; + for (var i=0; i Date: Fri, 4 Dec 2015 21:23:19 -0500 Subject: [PATCH 2/4] Add page setup --- bits/67_wsxml.js | 10 ++++++++++ xlsx.js | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/bits/67_wsxml.js b/bits/67_wsxml.js index 64a057e..1c4937c 100644 --- a/bits/67_wsxml.js +++ b/bits/67_wsxml.js @@ -70,6 +70,15 @@ function write_ws_xml_merges(merges) { return o + ''; } +function write_ws_xml_pagesetup(setup) { + return writextag('pageSetup', { + scale: setup.scale || 'scale', + orientation: setup.orientation || 'portrait', + horizontalDpi : setup.horizontalDpi || '4294967292', + verticalDpi : setup.verticalDpi || '4294967292' + }) +} + // // // @@ -326,6 +335,7 @@ function write_ws_xml(idx, opts, wb) { if (ws['!rowBreaks'] !== undefined) o[o.length] = write_ws_xml_row_breaks(ws['!rowBreaks']) if (ws['!colBreaks'] !== undefined) o[o.length] = write_ws_xml_col_breaks(ws['!colBreaks']) + if (ws['!pageSetup'] !== undefined) o[o.length] = write_ws_xml_pagesetup(ws['!pageSetup']) if(o.length>2) { o[o.length] = (''); o[1]=o[1].replace("/>",">"); } return o.join(""); diff --git a/xlsx.js b/xlsx.js index 19cf543..75f95db 100644 --- a/xlsx.js +++ b/xlsx.js @@ -7595,6 +7595,15 @@ function write_ws_xml_merges(merges) { return o + ''; } +function write_ws_xml_pagesetup(setup) { + return writextag('pageSetup', { + scale: setup.scale || 'scale', + orientation: setup.orientation || 'portrait', + horizontalDpi : setup.horizontalDpi || '4294967292', + verticalDpi : setup.verticalDpi || '4294967292' + }) +} + // // // @@ -7851,6 +7860,7 @@ function write_ws_xml(idx, opts, wb) { if (ws['!rowBreaks'] !== undefined) o[o.length] = write_ws_xml_row_breaks(ws['!rowBreaks']) if (ws['!colBreaks'] !== undefined) o[o.length] = write_ws_xml_col_breaks(ws['!colBreaks']) + if (ws['!pageSetup'] !== undefined) o[o.length] = write_ws_xml_pagesetup(ws['!pageSetup']) if(o.length>2) { o[o.length] = (''); o[1]=o[1].replace("/>",">"); } return o.join(""); From 0bf1153da50dca054c51276696dbb326c7b27dc2 Mon Sep 17 00:00:00 2001 From: Pieter Sheth-Voss Date: Fri, 4 Dec 2015 21:53:47 -0500 Subject: [PATCH 3/4] Add page scale and orientation --- README.md | 1 + bits/67_wsxml.js | 11 +++++++---- xlsx.js | 11 +++++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8c5ada2..358f542 100644 --- a/README.md +++ b/README.md @@ -419,6 +419,7 @@ Special worksheet keys (accessible as `worksheet[key]`, each starting with `!`): will write all cells in the merge range if they exist, so be sure that only the first cell (upper-left) in the range is set. +- `ws['!pageSetup']`: `{scale: '100', orientation: 'portrait'||'landscape'} ### Workbook Object `workbook.SheetNames` is an ordered list of the sheets in the workbook diff --git a/bits/67_wsxml.js b/bits/67_wsxml.js index 1c4937c..a7cef3c 100644 --- a/bits/67_wsxml.js +++ b/bits/67_wsxml.js @@ -71,12 +71,14 @@ function write_ws_xml_merges(merges) { } function write_ws_xml_pagesetup(setup) { - return writextag('pageSetup', { - scale: setup.scale || 'scale', + var pageSetup = writextag('pageSetup', null, { + scale: setup.scale || '100', orientation: setup.orientation || 'portrait', horizontalDpi : setup.horizontalDpi || '4294967292', verticalDpi : setup.verticalDpi || '4294967292' }) + console.log(pageSetup); + return pageSetup; } // @@ -333,9 +335,10 @@ function write_ws_xml(idx, opts, wb) { if(ws['!merges'] !== undefined && ws['!merges'].length > 0) o[o.length] = (write_ws_xml_merges(ws['!merges'])); + if (ws['!pageSetup'] !== undefined) o[o.length] = write_ws_xml_pagesetup(ws['!pageSetup']) if (ws['!rowBreaks'] !== undefined) o[o.length] = write_ws_xml_row_breaks(ws['!rowBreaks']) if (ws['!colBreaks'] !== undefined) o[o.length] = write_ws_xml_col_breaks(ws['!colBreaks']) - if (ws['!pageSetup'] !== undefined) o[o.length] = write_ws_xml_pagesetup(ws['!pageSetup']) + if(o.length>2) { o[o.length] = (''); o[1]=o[1].replace("/>",">"); } return o.join(""); @@ -356,7 +359,7 @@ function write_ws_xml_col_breaks(breaks) { var brk = []; for (var i=0; i @@ -7858,9 +7860,10 @@ function write_ws_xml(idx, opts, wb) { if(ws['!merges'] !== undefined && ws['!merges'].length > 0) o[o.length] = (write_ws_xml_merges(ws['!merges'])); + if (ws['!pageSetup'] !== undefined) o[o.length] = write_ws_xml_pagesetup(ws['!pageSetup']) if (ws['!rowBreaks'] !== undefined) o[o.length] = write_ws_xml_row_breaks(ws['!rowBreaks']) if (ws['!colBreaks'] !== undefined) o[o.length] = write_ws_xml_col_breaks(ws['!colBreaks']) - if (ws['!pageSetup'] !== undefined) o[o.length] = write_ws_xml_pagesetup(ws['!pageSetup']) + if(o.length>2) { o[o.length] = (''); o[1]=o[1].replace("/>",">"); } return o.join(""); @@ -7881,7 +7884,7 @@ function write_ws_xml_col_breaks(breaks) { var brk = []; for (var i=0; i Date: Fri, 4 Dec 2015 23:15:03 -0500 Subject: [PATCH 4/4] Add doc props --- README.md | 10 ++++++++-- bits/33_coreprops.js | 21 ++++++++++++++------- xlsx.js | 21 ++++++++++++++------- 3 files changed, 36 insertions(+), 16 deletions(-) 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) */