Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing font color while adding row in exceljs

Tags:

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?

like image 962
Srujan Reddy Avatar asked Dec 05 '22 14:12

Srujan Reddy


1 Answers

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"}};
    });
});
like image 174
Srujan Reddy Avatar answered Jan 05 '23 15:01

Srujan Reddy