3

To apply fill to a particular cell exceljs doc helped me with the below code.

worksheet.getCell('A1').fill = {
                type: 'pattern',
                pattern:'solid',
                fgColor:{argb:'FF0'}
            };

But to apply fill to a range of cells there is no documentation and also can't find with a google search.

SO-user
  • 1,458
  • 2
  • 21
  • 43

2 Answers2

8

I'm facing the same problem and I solved it using map. Here is my code example:

// fill the cell with BLUE
    ['B1',
    'C1',
    'D1',
    'E1',
    'F1',
    'G1',
    'H1',
    'I1'].map(key => {
      worksheet.getCell(key).fill = {
        type: 'pattern',
        pattern: 'solid',
        fgColor: { argb: '96C8FB' },
        bgColor: { argb: '96C8FB' }
      };
});
Alberto AM
  • 310
  • 2
  • 12
5

// this is to set fill for every cell (upto last column) in a row

worksheet.getRow(2).eachCell({ includeEmpty: true }, function(cell) {
  worksheet.getCell(cell.address).fill = {
    type: 'pattern',
    pattern: 'gray125',
  }
})
user3692136
  • 51
  • 1
  • 1