Skip to content

Commit

Permalink
Merge pull request exceljs#320 from psellers89/master
Browse files Browse the repository at this point in the history
Add printTitlesRow Support
  • Loading branch information
guyonroche authored May 21, 2017
2 parents 48ac18e + d5a7613 commit fc1ea97
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ worksheet.pageSetup.margins = {
// Set Print Area for a sheet
worksheet.pageSetup.printArea = 'A1:G20';

// Repeat specific rows on every printed page
worksheet.pageSetup.printTitlesRow = '1:3';

```

**Supported pageSetup settings**
Expand Down Expand Up @@ -1712,4 +1715,4 @@ 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> |
12 changes: 12 additions & 0 deletions lib/xlsx/xform/book/workbook-xform.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ utils.inherits(WorkbookXform, BaseXform, {
};
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);
}
index++;
});
if (printAreas.length) {
Expand Down
28 changes: 28 additions & 0 deletions test/testWbXform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

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);
});

0 comments on commit fc1ea97

Please sign in to comment.