exceljs

Changing font color while adding row in exceljs


As per the documentation, Changing font color of a particular cell is possible in this way:

sheet.addRow([
    'alex', 
    {
        text: 'image',
        hyperlink: 'http://something.com' //trying to change color of this cell
    }
])

sheet.getRow(1).getCell(2).font = {color: {argb: "004e47cc"}};

But, How do i specify styles while adding a row itself. (something like below).

sheet.addRow([
    'alex', 
    {
        text: 'image', 
        hyperlink: 'http://something.com', 
        font: {color: {argb: '004e47cc'}}
    }
])

My ultimate goal is to change color and underline all Hyperlinks in the sheet (**Hyperlinks are in random cells). Is there a better solution?


Solution

  • This works:

    sheet.eachRow(function(row, rowNumber){
        row.eachCell( function(cell, colNumber){
            if(cell.value && cell.value.hyperlink)
                row.getCell(colNumber).font = {color: {argb: "004e47cc"}};
        });
    });