From 2239977b072e62f3e9edcdc923da1992eb8b7ef0 Mon Sep 17 00:00:00 2001
From: guyonroche
Date: Sun, 21 May 2017 19:35:46 +0100
Subject: [PATCH] Fixed reconcile, added integration-test
---
README.md | 14 ++++----
lib/doc/worksheet.js | 26 +++++++--------
lib/stream/xlsx/worksheet-reader.js | 14 ++++++++
lib/stream/xlsx/worksheet-writer.js | 15 +++++++++
lib/xlsx/xform/book/workbook-xform.js | 39 +++++++++++++---------
spec/integration/workbook/workbook.spec.js | 23 +++++++++++++
spec/utils/index.js | 15 ++++++++-
test/testWbXform.js | 28 ----------------
8 files changed, 110 insertions(+), 64 deletions(-)
delete mode 100644 test/testWbXform.js
diff --git a/README.md b/README.md
index 469ad5727..0584e4143 100644
--- a/README.md
+++ b/README.md
@@ -12,14 +12,12 @@ npm install exceljs
-
- Switching to transpiled code for distribution.
- This will ensure compatability with 4.0.0 and above from here on.
- And it will also allow use of much more expressive JS code in the lib folder!
+ Merged Add missing Office Rels #319
+ Thanks goes to mauriciovillalobos for the contribution.
-
- Basic Image Support!
- Images can now be added to worksheets either as a tiled background or stretched over a range.
- Note: other features like rotation, etc. are not supported yet and will reqeuire further work.
+ Merged Add printTitlesRow Support #320
+ Thanks goes to psellers89 for the contribution.
@@ -1715,4 +1713,6 @@ If any splice operation affects a merged cell, the merge group will not be moved
| 0.4.2 |
Regarding themes: the theme files stored inside the xlsx container hold important information regarding colours, styles etc and if the theme information from a loaded xlsx file is lost, the results can be unpredictable and undesirable. To address this, when an ExcelJS Workbook parses an XLSX file, it will preserve any theme files it finds and include them when writing to a new XLSX. If this behaviour is not desired, the Workbook class exposes a clearThemes() function which will drop the theme content. Note that this behaviour is only implemented in the document based Workbook class, not the streamed Reader and Writer.
|
| 0.4.3 | |
| 0.4.4 | |
-| 0.4.6 | |
\ No newline at end of file
+| 0.4.6 | |
+| 0.4.9 | - Switching to transpiled code for distribution. This will ensure compatability with 4.0.0 and above from here on. And it will also allow use of much more expressive JS code in the lib folder!
- Basic Image Support!Images can now be added to worksheets either as a tiled background or stretched over a range. Note: other features like rotation, etc. are not supported yet and will reqeuire further work.
|
+
\ No newline at end of file
diff --git a/lib/doc/worksheet.js b/lib/doc/worksheet.js
index d99672e07..a578ed8c7 100644
--- a/lib/doc/worksheet.js
+++ b/lib/doc/worksheet.js
@@ -122,19 +122,6 @@ Worksheet.prototype = {
return this._columns;
},
- getColumnKey(key) {
- return this._keys[key];
- },
- setColumnKey(key, value) {
- this._keys[key] = value;
- },
- deleteColumnKey(key) {
- delete this._keys[key];
- },
- eachColumnKey(f) {
- _.each(this._keys, f);
- },
-
// set the columns from an array of column definitions.
// Note: any headers defined will overwrite existing values.
set columns(value) {
@@ -159,6 +146,19 @@ Worksheet.prototype = {
});
},
+ getColumnKey(key) {
+ return this._keys[key];
+ },
+ setColumnKey(key, value) {
+ this._keys[key] = value;
+ },
+ deleteColumnKey(key) {
+ delete this._keys[key];
+ },
+ eachColumnKey(f) {
+ _.each(this._keys, f);
+ },
+
// get a single column by col number. If it doesn't exist, create it and any gaps before it
getColumn: function(c) {
if (typeof c === 'string') {
diff --git a/lib/stream/xlsx/worksheet-reader.js b/lib/stream/xlsx/worksheet-reader.js
index 17b0c33f9..fc1f326d8 100644
--- a/lib/stream/xlsx/worksheet-reader.js
+++ b/lib/stream/xlsx/worksheet-reader.js
@@ -9,6 +9,7 @@
var events = require('events');
var Sax = require('sax');
+var _ = require('../../utils/under-dash');
var utils = require('../../utils/utils');
var colCache = require('../../utils/col-cache');
var Dimensions = require('../../doc/range');
@@ -73,6 +74,19 @@ utils.inherits(WorksheetReader, events.EventEmitter, {
return this._columns[c - 1];
},
+ getColumnKey(key) {
+ return this._keys[key];
+ },
+ setColumnKey(key, value) {
+ this._keys[key] = value;
+ },
+ deleteColumnKey(key) {
+ delete this._keys[key];
+ },
+ eachColumnKey(f) {
+ _.each(this._keys, f);
+ },
+
// =========================================================================
// Read
diff --git a/lib/stream/xlsx/worksheet-writer.js b/lib/stream/xlsx/worksheet-writer.js
index 13421ef5e..24a7d6c97 100644
--- a/lib/stream/xlsx/worksheet-writer.js
+++ b/lib/stream/xlsx/worksheet-writer.js
@@ -6,6 +6,8 @@
'use strict';
+var _ = require('../../utils/under-dash');
+
var RelType = require('../../xlsx/rel-type');
var colCache = require('../../utils/col-cache');
@@ -257,6 +259,19 @@ WorksheetWriter.prototype = {
});
},
+ getColumnKey(key) {
+ return this._keys[key];
+ },
+ setColumnKey(key, value) {
+ this._keys[key] = value;
+ },
+ deleteColumnKey(key) {
+ delete this._keys[key];
+ },
+ eachColumnKey(f) {
+ _.each(this._keys, f);
+ },
+
// get a single column by col number. If it doesn't exist, it and any gaps before it
// are created.
getColumn: function(c) {
diff --git a/lib/xlsx/xform/book/workbook-xform.js b/lib/xlsx/xform/book/workbook-xform.js
index 5711a642c..0faaf05a2 100644
--- a/lib/xlsx/xform/book/workbook-xform.js
+++ b/lib/xlsx/xform/book/workbook-xform.js
@@ -53,25 +53,22 @@ utils.inherits(WorkbookXform, BaseXform, {
var index = 0; // sheets is sparse array - calc index manually
model.sheets.forEach(function(sheet) {
if (sheet.pageSetup && sheet.pageSetup.printArea) {
- var definedName = {
+ const definedName = {
name: '_xlnm.Print_Area',
- ranges: ['\'' + sheet.name + '\'!' + sheet.pageSetup.printArea],
+ ranges: [sheet.name + '!' + sheet.pageSetup.printArea],
localSheetId: index
};
printAreas.push(definedName);
}
if (sheet.pageSetup && sheet.pageSetup.printTitlesRow) {
-
- var titlesRows = sheet.pageSetup.printTitlesRow.split(':');
-
- var definedName = {
- name: '_xlnm.Print_Titles',
-
- ranges: ['\'' + sheet.name + '\'!$' + titlesRows[0] + ':$' + titlesRows[1]],
- localSheetId: index
- };
- printAreas.push(definedName);
- }
+ const titlesRows = sheet.pageSetup.printTitlesRow.split(':');
+ const definedName = {
+ name: '_xlnm.Print_Titles',
+ ranges: ['\'' + sheet.name + '\'!$' + titlesRows[0] + ':$' + titlesRows[1]],
+ localSheetId: index
+ };
+ printAreas.push(definedName);
+ }
index++;
});
if (printAreas.length) {
@@ -172,10 +169,22 @@ utils.inherits(WorkbookXform, BaseXform, {
if (definedName.name === '_xlnm.Print_Area') {
worksheet = worksheets[definedName.localSheetId];
if (worksheet) {
- if (!worksheet.pageSetup) { worksheet.pageSetup = {}; }
- var range = colCache.decodeEx(definedName.ranges[0]);
+ if (!worksheet.pageSetup) {
+ worksheet.pageSetup = {};
+ }
+ const range = colCache.decodeEx(definedName.ranges[0]);
worksheet.pageSetup.printArea = range.dimensions;
}
+ } else if (definedName.name === '_xlnm.Print_Titles') {
+ worksheet = worksheets[definedName.localSheetId];
+ if (worksheet) {
+ if (!worksheet.pageSetup) {
+ worksheet.pageSetup = {};
+ }
+ const longRange = definedName.ranges[0].split('!');
+ const range = longRange[longRange.length - 1];
+ worksheet.pageSetup.printTitlesRow = range;
+ }
} else {
definedNames.push(definedName);
}
diff --git a/spec/integration/workbook/workbook.spec.js b/spec/integration/workbook/workbook.spec.js
index ab99a128a..fc29bcde6 100644
--- a/spec/integration/workbook/workbook.spec.js
+++ b/spec/integration/workbook/workbook.spec.js
@@ -72,6 +72,29 @@ describe('Workbook', function() {
expect(wb2.modified).to.equalDate(wb.modified);
});
});
+ it('printTitlesRow', function() {
+ var wb = new Excel.Workbook();
+ var ws = wb.addWorksheet('printHeader');
+
+ ws.getCell('A1').value = 'This is a header row repeated on every printed page';
+ ws.getCell('B2').value = 'This is a header row too';
+
+ for (var i = 0; i < 100; i++) {
+ ws.addRow(['not header row']);
+ }
+
+ ws.pageSetup.printTitlesRow = '1:2';
+
+ return wb.xlsx.writeFile(TEST_XLSX_FILE_NAME)
+ .then(function() {
+ var wb2 = new Excel.Workbook();
+ return wb2.xlsx.readFile(TEST_XLSX_FILE_NAME);
+ })
+ .then(function(wb2) {
+ var ws2 = wb2.getWorksheet('printHeader');
+ expect(ws2.pageSetup.printTitlesRow).to.equal('$1:$2');
+ });
+ });
it('shared formula', function() {
var wb = new Excel.Workbook();
diff --git a/spec/utils/index.js b/spec/utils/index.js
index 9deff82b7..698fcd6ea 100644
--- a/spec/utils/index.js
+++ b/spec/utils/index.js
@@ -122,7 +122,20 @@ module.exports = {
},
getCell: function(rowNumber, colNumber) {
return this.getRow(rowNumber).getCell(colNumber);
- }
+ },
+ getColumnKey(key) {
+ return this._keys[key];
+ },
+ setColumnKey(key, value) {
+ this._keys[key] = value;
+ },
+ deleteColumnKey(key) {
+ delete this._keys[key];
+ },
+ eachColumnKey(f) {
+ _.each(this._keys, f);
+ },
+
};
}
};
diff --git a/test/testWbXform.js b/test/testWbXform.js
deleted file mode 100644
index 76160e45a..000000000
--- a/test/testWbXform.js
+++ /dev/null
@@ -1,28 +0,0 @@
-
-var Excel = require('../excel');
-
-var filename = process.argv[2];
-
-var wb = new Excel.Workbook();
-
-var ws = wb.addWorksheet('printHeader');
-
-
-ws.getCell('A1').value = 'This is a header row repeated on every printed page';
-ws.getCell('B2').value = 'This is a header row too';
-
-for (var i=0 ; i < 100 ; i++){
- ws.addRow(['not header row']);
-};
-
-
-ws.pageSetup.printTitlesRow = '1:2';
-
-
-wb.xlsx.writeFile(filename)
- .then(function() {
- console.log('Done.');
- })
- .catch(function(error) {
- console.log(error.message);
- });
\ No newline at end of file