Search code examples
javascriptexcelexceljs

exceljs - Apply fill to cell range


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.


Solution

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