From da1553617300a58af02fc25ed411bb4b28684a82 Mon Sep 17 00:00:00 2001 From: cxam Date: Sun, 3 Feb 2019 13:39:17 +0000 Subject: [PATCH 1/2] Copy row styles --- lib/doc/worksheet.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/doc/worksheet.js b/lib/doc/worksheet.js index 3b43e3b03..31a4eec5a 100644 --- a/lib/doc/worksheet.js +++ b/lib/doc/worksheet.js @@ -330,6 +330,10 @@ Worksheet.prototype = { rSrc = this._rows[i - 1]; if (rSrc) { this.getRow(i + nExpand).values = rSrc.values; + // eslint-disable-next-line no-loop-func + rSrc.eachCell({ includeEmpty: true }, function(cell, colNumber) { + this.getRow(i + nExpand).getCell(colNumber).style = cell.style; + }.bind(this)); this._rows[i - 1] = undefined; } else { this._rows[(i + nExpand) - 1] = undefined; @@ -341,6 +345,10 @@ Worksheet.prototype = { rSrc = this._rows[i - 1]; if (rSrc) { this.getRow(i + nExpand).values = rSrc.values; + // eslint-disable-next-line no-loop-func + rSrc.eachCell({ includeEmpty: true }, function(cell, colNumber) { + this.getRow(i + nExpand).getCell(colNumber).style = cell.style; + }.bind(this)); } else { this._rows[(i + nExpand) - 1] = undefined; } From d57d9c85e6dedf9436cedcc01f130515cff58800 Mon Sep 17 00:00:00 2001 From: cxam Date: Sun, 3 Feb 2019 13:40:10 +0000 Subject: [PATCH 2/2] Update spliced sheet tests to check row styles --- spec/integration/workbook/workbook.spec.js | 1 + spec/unit/doc/worksheet.values.spec.js | 5 +++ spec/utils/test-spliced-sheet.js | 47 +++++++++++++++++++++- 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/spec/integration/workbook/workbook.spec.js b/spec/integration/workbook/workbook.spec.js index 61b063a65..28b2e093a 100644 --- a/spec/integration/workbook/workbook.spec.js +++ b/spec/integration/workbook/workbook.spec.js @@ -487,6 +487,7 @@ describe('Workbook', function() { 'splice.rows.insertFewer', 'splice.rows.insertSame', 'splice.rows.insertMore', + 'splice.rows.insertStyle', 'splice.columns.removeOnly', 'splice.columns.insertFewer', 'splice.columns.insertSame', diff --git a/spec/unit/doc/worksheet.values.spec.js b/spec/unit/doc/worksheet.values.spec.js index 31e624329..5da5cd038 100644 --- a/spec/unit/doc/worksheet.values.spec.js +++ b/spec/unit/doc/worksheet.values.spec.js @@ -346,6 +346,11 @@ describe('Worksheet', function() { testUtils.createTestBook(wb, 'xlsx', ['splice.rows.insertMore'], options); testUtils.checkTestBook(wb, 'xlsx', ['splice.rows.insertMore'], options); }); + it('Insert style', function() { + var wb = new Excel.Workbook(); + testUtils.createTestBook(wb, 'xlsx', ['splice.rows.insertStyle'], options); + testUtils.checkTestBook(wb, 'xlsx', ['splice.rows.insertStyle'], options); + }); }); describe('Columns', function() { it('splices columns', function() { diff --git a/spec/utils/test-spliced-sheet.js b/spec/utils/test-spliced-sheet.js index 027971493..1fc20f94c 100644 --- a/spec/utils/test-spliced-sheet.js +++ b/spec/utils/test-spliced-sheet.js @@ -128,7 +128,52 @@ module.exports = { expect(ws.getRow(5).values).to.deep.equal([, 4.1,, 4.3]); expect(ws.getRow(6).values).to.deep.equal([, '5,1', '5,2', '5,3']); } - } + }, + insertStyle: { + addSheet: function(wb) { + var ws = wb.addWorksheet('splice-row-insert-style'); + + ws.addRow(['1,1', '1,2', '1,3']); + ws.addRow(['2,1', '2,2', '2,3']); + ws.getCell('A2').fill = { + type: 'pattern', + pattern:'darkVertical', + fgColor: { argb:'FFFF0000' } + }; + + ws.spliceRows(2, 0, ['one', 'two', 'three']); + ws.getCell('A2').border = { + top: { style:'thin' }, + left: { style:'thin' }, + bottom: { style:'thin' }, + right: { style:'thin' } + }; + }, + + checkSheet: function(wb) { + var ws = wb.getWorksheet('splice-row-insert-style'); + expect(ws).to.not.be.undefined(); + + expect(ws.getRow(1).values).to.deep.equal([, '1,1', '1,2', '1,3']); + expect(ws.getRow(2).values).to.deep.equal([, 'one', 'two', 'three']); + expect(ws.getRow(3).values).to.deep.equal([, '2,1', '2,2', '2,3']); + expect(ws.getCell('A2').style).to.deep.equal({ + border: { + top: { style:'thin' }, + left: { style:'thin' }, + bottom: { style:'thin' }, + right: { style:'thin' } + } + }); + expect(ws.getCell('A3').style).to.deep.equal({ + fill: { + type: 'pattern', + pattern:'darkVertical', + fgColor: { argb:'FFFF0000' } + } + }); + } + }, }, columns: { removeOnly: {