6

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?

Srujan Reddy
  • 730
  • 1
  • 6
  • 27

2 Answers2

9

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"}};
    });
});
Srujan Reddy
  • 730
  • 1
  • 6
  • 27
8

It is indeed possible to change the background color when adding a row;

let row = workSheet.addRow(rowValues);
            row.fill = {
                type: 'pattern',
                pattern:'solid',
                fgColor:{argb:'#000000'},
                bgColor:{argb:'#FF0000'}
            };
code_kbd
  • 450
  • 4
  • 11
  • 4
    For the colors use them without the # otherwise youll get a black background color. SO it should be something like row1.fill = { type: 'pattern', pattern:'solid', fgColor: { argb:'FFFF0000' } }; – Geoff Sep 30 '19 at 18:32
  • thanks for the comment @geoff. I did not edit the answer since your comment makes it very clear. In my case, I wanted a black solid color, so I really did not notice it. – code_kbd Jun 04 '20 at 02:08
  • Hi @code_kbd, i am trying to do something similar, where i am reading from one excel and writing to another excel with using `addRow`. Do you know how i can copy the cell styling when adding row? here is the question link https://stackoverflow.com/questions/65309694/styles-not-getting-copied-from-source-excel-file any help would be really great, Thanks. – opensource-developer Dec 15 '20 at 16:56
  • 1
    this is not working. We need to loop through all the cells in that row and then add the font property to it. That is the only working solution as of now. – anil kumar d Aug 17 '21 at 12:48