11'use strict' ;
22
3- var verquire = require ( '../utils/verquire' ) ;
4- var testutils = require ( '../utils/index' ) ;
5- var fs = require ( 'fs' ) ;
6- var expect = require ( 'chai' ) . expect ;
3+ const verquire = require ( '../utils/verquire' ) ;
4+ const testutils = require ( '../utils/index' ) ;
5+ const fs = require ( 'fs' ) ;
6+ const expect = require ( 'chai' ) . expect ;
77
8- var Excel = verquire ( 'excel' ) ;
8+ const Excel = verquire ( 'excel' ) ;
99
10- var TEST_FILE_NAME = './spec/out/wb.test.xlsx' ;
10+ const TEST_FILE_NAME = './spec/out/wb.test.xlsx' ;
1111
1212// need some architectural changes to make stream read work properly
1313// because of: shared strings, sheet names, etc are not read in guaranteed order
1414describe ( 'WorkbookReader' , function ( ) {
1515 describe ( 'Serialise' , function ( ) {
1616 it ( 'xlsx file' , function ( ) {
1717 this . timeout ( 10000 ) ;
18- var wb = testutils . createTestBook ( new Excel . Workbook ( ) , 'xlsx' ) ;
18+ const wb = testutils . createTestBook ( new Excel . Workbook ( ) , 'xlsx' ) ;
1919
2020 return wb . xlsx . writeFile ( TEST_FILE_NAME )
2121 . then ( function ( ) {
@@ -27,7 +27,7 @@ describe('WorkbookReader', function() {
2727 describe ( '#readFile' , function ( ) {
2828 describe ( 'Row limit' , function ( ) {
2929 it ( 'should bail out if the file contains more rows than the limit' , function ( ) {
30- var workbook = new Excel . Workbook ( ) ;
30+ const workbook = new Excel . Workbook ( ) ;
3131 // The Fibonacci sheet has 19 rows
3232 return workbook . xlsx . readFile ( './spec/integration/data/fibonacci.xlsx' , { maxRows : 10 } )
3333 . then ( function ( ) {
@@ -39,7 +39,7 @@ describe('WorkbookReader', function() {
3939
4040 it ( 'should fail fast on a huge file' , function ( ) {
4141 this . timeout ( 20000 ) ;
42- var workbook = new Excel . Workbook ( ) ;
42+ const workbook = new Excel . Workbook ( ) ;
4343 return workbook . xlsx . readFile ( './spec/integration/data/huge.xlsx' , { maxRows : 100 } )
4444 . then ( function ( ) {
4545 throw new Error ( 'Promise unexpectedly fulfilled' ) ;
@@ -49,7 +49,7 @@ describe('WorkbookReader', function() {
4949 } ) ;
5050
5151 it ( 'should parse fine if the limit is not exceeded' , function ( ) {
52- var workbook = new Excel . Workbook ( ) ;
52+ const workbook = new Excel . Workbook ( ) ;
5353 return workbook . xlsx . readFile ( './spec/integration/data/fibonacci.xlsx' , { maxRows : 20 } ) ;
5454 } ) ;
5555 } ) ;
@@ -58,7 +58,7 @@ describe('WorkbookReader', function() {
5858 describe ( '#read' , function ( ) {
5959 describe ( 'Row limit' , function ( ) {
6060 it ( 'should bail out if the file contains more rows than the limit' , function ( ) {
61- var workbook = new Excel . Workbook ( ) ;
61+ const workbook = new Excel . Workbook ( ) ;
6262 // The Fibonacci sheet has 19 rows
6363 return workbook . xlsx . read ( fs . createReadStream ( './spec/integration/data/fibonacci.xlsx' ) , { maxRows : 10 } )
6464 . then ( function ( ) {
@@ -69,16 +69,39 @@ describe('WorkbookReader', function() {
6969 } ) ;
7070
7171 it ( 'should parse fine if the limit is not exceeded' , function ( ) {
72- var workbook = new Excel . Workbook ( ) ;
72+ const workbook = new Excel . Workbook ( ) ;
7373 return workbook . xlsx . read ( fs . createReadStream ( './spec/integration/data/fibonacci.xlsx' ) , { maxRows : 20 } ) ;
7474 } ) ;
7575 } ) ;
7676 } ) ;
77+
78+ describe ( 'edit styles in existing file' , function ( ) {
79+ beforeEach ( function ( ) {
80+ this . wb = new Excel . Workbook ( ) ;
81+ return this . wb . xlsx . readFile ( './spec/integration/data/test-row-styles.xlsx' ) ;
82+ } ) ;
83+
84+ it ( 'edit styles of single row instead of all' , function ( ) {
85+ const ws = this . wb . getWorksheet ( 1 ) ;
86+
87+ ws . eachRow ( ( row , rowNo ) => {
88+ rowNo % 5 === 0 && ( row . font = { color : { argb : '00ff00' } } )
89+ } ) ;
90+
91+ expect ( ws . getRow ( 3 ) . font . color . argb ) . to . be . equal ( ws . getRow ( 6 ) . font . color . argb ) ;
92+ expect ( ws . getRow ( 6 ) . font . color . argb ) . to . be . equal ( ws . getRow ( 9 ) . font . color . argb ) ;
93+ expect ( ws . getRow ( 9 ) . font . color . argb ) . to . be . equal ( ws . getRow ( 12 ) . font . color . argb ) ;
94+ expect ( ws . getRow ( 12 ) . font . color . argb ) . not . to . be . equal ( ws . getRow ( 15 ) . font . color . argb ) ;
95+ expect ( ws . getRow ( 15 ) . font . color . argb ) . not . to . be . equal ( ws . getRow ( 18 ) . font . color . argb ) ;
96+ expect ( ws . getRow ( 15 ) . font . color . argb ) . to . be . equal ( ws . getRow ( 10 ) . font . color . argb ) ;
97+ expect ( ws . getRow ( 10 ) . font . color . argb ) . to . be . equal ( ws . getRow ( 5 ) . font . color . argb ) ;
98+ } )
99+ } ) ;
77100
78101 describe ( 'with a spreadsheet that contains formulas' , function ( ) {
79102 before ( function ( ) {
80- var testContext = this ;
81- var workbook = new Excel . Workbook ( ) ;
103+ const testContext = this ;
104+ const workbook = new Excel . Workbook ( ) ;
82105 return workbook . xlsx . read ( fs . createReadStream ( './spec/integration/data/formulas.xlsx' ) )
83106 . then ( function ( ) {
84107 testContext . worksheet = workbook . getWorksheet ( ) ;
@@ -129,8 +152,8 @@ describe('WorkbookReader', function() {
129152
130153 describe ( 'with a spreadsheet that contains a shared string with an escaped underscore' , function ( ) {
131154 before ( function ( ) {
132- var testContext = this ;
133- var workbook = new Excel . Workbook ( ) ;
155+ const testContext = this ;
156+ const workbook = new Excel . Workbook ( ) ;
134157 return workbook . xlsx . read ( fs . createReadStream ( './spec/integration/data/shared_string_with_escape.xlsx' ) )
135158 . then ( function ( ) {
136159 testContext . worksheet = workbook . getWorksheet ( ) ;
0 commit comments