Exceljs: set style for range?

Created on 16 Jun 2017  ·  3Comments  ·  Source: exceljs/exceljs

I would like to set style for range ...(A1:D10).style.....

help wanted resolved

Most helpful comment

Here is how I've apply style to range:

['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1'].map(key => {
        sheet.getCell(key).fill = {
            type: 'pattern',
            pattern:'solid',
            fgColor:{argb:'cccccc'}
        };
    });

All 3 comments

I have written this little function that styles certain columns of a row, I suppose you can easily extend it.

    var cell;

    var styleColumnsInRow = function(row, keys, styles){
         _.each(keys, function(key){
             cell = row.getCell(key);

             _.each(styles, function(style){
                cell[style.key] = style.value;
              });
          });
     };

You can call it like that:

     var row = sheet.getRow(1);
     var columns = ['amount','price','color']; 
     var styles = [{key: 'border', value: {bottom: {style: 'double'}}}];

     styleColumnsInRow(row, columns, styles);

That will give the three columns double border in the bottom.

Here is how I've apply style to range:

['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1'].map(key => {
        sheet.getCell(key).fill = {
            type: 'pattern',
            pattern:'solid',
            fgColor:{argb:'cccccc'}
        };
    });

441 #180

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lukelaws picture lukelaws  ·  3Comments

MR4online picture MR4online  ·  3Comments

dm-ibtissam picture dm-ibtissam  ·  4Comments

Siemienik picture Siemienik  ·  4Comments

dbsxdbsx picture dbsxdbsx  ·  3Comments