Skip to content

Commit

Permalink
Reordered hyperlinks and cell merging
Browse files Browse the repository at this point in the history
When both used at once, hyperlinks and cell merging conflict - they
need to be reordered
  • Loading branch information
saperdadsk committed May 24, 2016
1 parent 4acbea0 commit dc45597
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/Excel/Worksheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,18 @@ var SheetView = require('./SheetView');
worksheet.appendChild(this.sheetProtection.exportXML(doc));
}

// 'mergeCells' should be written before 'hyperlinks', 'headerFoot', and 'drawing' due to issue
// with Microsoft Excel (2007, 2013)
if (this.mergedCells.length > 0) {
var mergeCells = doc.createElement('mergeCells');
for (i = 0, l = this.mergedCells.length; i < l; i++) {
var mergeCell = doc.createElement('mergeCell');
mergeCell.setAttribute('ref', this.mergedCells[i][0] + ':' + this.mergedCells[i][1]);
mergeCells.appendChild(mergeCell);
}
worksheet.appendChild(mergeCells);
}

/**
* Doing this a bit differently, as hyperlinks could be as populous as rows. Looping twice would be bad.
*/
Expand All @@ -405,18 +417,6 @@ var SheetView = require('./SheetView');
worksheet.appendChild(hyperlinksEl);
}

// 'mergeCells' should be written before 'headerFoot' and 'drawing' due to issue
// with Microsoft Excel (2007, 2013)
if (this.mergedCells.length > 0) {
var mergeCells = doc.createElement('mergeCells');
for (i = 0, l = this.mergedCells.length; i < l; i++) {
var mergeCell = doc.createElement('mergeCell');
mergeCell.setAttribute('ref', this.mergedCells[i][0] + ':' + this.mergedCells[i][1]);
mergeCells.appendChild(mergeCell);
}
worksheet.appendChild(mergeCells);
}

this.exportPageSettings(doc, worksheet);

if(this._headers.length > 0 || this._footers.length > 0) {
Expand Down

0 comments on commit dc45597

Please sign in to comment.