Skip to content

Commit

Permalink
Fixed reconcile, added integration-test
Browse files Browse the repository at this point in the history
  • Loading branch information
guyonroche committed May 21, 2017
1 parent fc1ea97 commit 2239977
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 64 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ npm install exceljs

<ul>
<li>
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 <a href="https://github.com/guyonroche/exceljs/pull/319">Add missing Office Rels #319</a>
Thanks goes to <a href="https://github.com/mauriciovillalobos">mauriciovillalobos</a> for the contribution.
</li>
<li>
<a href="#images">Basic Image Support!</a>
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 <a href="https://github.com/guyonroche/exceljs/pull/320">Add printTitlesRow Support #320</a>
Thanks goes to <a href="https://github.com/psellers89">psellers89</a> for the contribution.
</li>
</ul>

Expand Down Expand Up @@ -1715,4 +1713,6 @@ If any splice operation affects a merged cell, the merge group will not be moved
| 0.4.2 | <ul><li><p>Addressed the following issues:<ul><li><a href="https://github.com/guyonroche/exceljs/issues/290">White text and borders being changed to black #290</a></li><li><a href="https://github.com/guyonroche/exceljs/issues/261">Losing formatting/pivot table from loaded file #261</a></li><li><a href="https://github.com/guyonroche/exceljs/issues/272">Solid fill become black #272</a></li></ul>These issues are potentially caused by a bug that caused colours with zero themes, tints or indexes to be rendered and parsed incorrectly.</p><p>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.</p></li></ul> |
| 0.4.3 | <ul><li>Merged <a href="https://github.com/guyonroche/exceljs/pull/294">Support error references in cell ranges #294</a>. Thanks to <a href="https://github.com/holm">holm</a> for the contribution.</li></ul> |
| 0.4.4 | <ul><li>Merged <a href="https://github.com/guyonroche/exceljs/pull/297">Issue with copied cells #297</a>. This merge adds support for shared formulas. Thanks to <a href="https://github.com/muscapades">muscapades</a> for the contribution.</li></ul> |
| 0.4.6 | <ul><li>Merged <a href="https://github.com/guyonroche/exceljs/pull/304">Correct spelling #304</a>. Thanks to <a href="https://github.com/toanalien">toanalien</a> for the contribution.</li><li>Merged <a href="https://github.com/guyonroche/exceljs/pull/304">Added support for auto filters #306</a>. This adds <a href="#auto-filters">Auto Filters</a> to the Worksheet. Thanks to <a href="https://github.com/C4rmond4i">C4rmond4i</a> for the contribution.</li><li>Restored NodeJS 4.0.0 compatability by removing the destructuring code. My apologies for any inconvenience.</li></ul> |
| 0.4.6 | <ul><li>Merged <a href="https://github.com/guyonroche/exceljs/pull/304">Correct spelling #304</a>. Thanks to <a href="https://github.com/toanalien">toanalien</a> for the contribution.</li><li>Merged <a href="https://github.com/guyonroche/exceljs/pull/304">Added support for auto filters #306</a>. This adds <a href="#auto-filters">Auto Filters</a> to the Worksheet. Thanks to <a href="https://github.com/C4rmond4i">C4rmond4i</a> for the contribution.</li><li>Restored NodeJS 4.0.0 compatability by removing the destructuring code. My apologies for any inconvenience.</li></ul> |
| 0.4.9 | <ul><li>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!</li><li><a href="#images">Basic Image Support!</a>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.</li></ul> |

26 changes: 13 additions & 13 deletions lib/doc/worksheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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') {
Expand Down
14 changes: 14 additions & 0 deletions lib/stream/xlsx/worksheet-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions lib/stream/xlsx/worksheet-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

'use strict';

var _ = require('../../utils/under-dash');

var RelType = require('../../xlsx/rel-type');

var colCache = require('../../utils/col-cache');
Expand Down Expand Up @@ -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) {
Expand Down
39 changes: 24 additions & 15 deletions lib/xlsx/xform/book/workbook-xform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
23 changes: 23 additions & 0 deletions spec/integration/workbook/workbook.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 14 additions & 1 deletion spec/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},

};
}
};
28 changes: 0 additions & 28 deletions test/testWbXform.js

This file was deleted.

0 comments on commit 2239977

Please sign in to comment.