How to make header row bold using xlsx / SheetJS

Based on our previous example How to make cell bold using xlsx / SheetJS, the following code example will set {s: {font: {bold: true}} for every cell of the first row.

This code assumes that you know the number of columns (header.length in this example).

Add the following code after adding the cell content to the worksheet.

// Make first row bold
for(let i = 0; i < headers.length; i++) {
    const cell = ws[XLSX.utils.encode_cell({r: 0, c: i})];
    // Create new style if cell doesnt have a style yet
    if(!cell.s) {cell.s = {};}
    if(!cell.s.font) {cell.s.font = {};}
    // Set bold
    cell.s.font.bold = true;
}