How to make cell bold using xlsx / SheetJS

First, you need to understand that stock xlsx / SheetJS community edition does not support cell styling as of August 2023.

Hence, you need to use the fork xlsx-js-style which you can install using

npm i --save xlsx-js-style

Now, based on our previous example, use these imports

import * as XLSX from 'xlsx-js-style';
import { saveAs } from 'file-saver';

and this code to generate a XLSX file with a bold cell:

// Create an empty workbook
const wb = XLSX.utils.book_new();

// Create an empty worksheet
// If this weren't a minimal example, your data would go here
const ws = XLSX.utils.aoa_to_sheet([
    ["Test"]
]);

// Make cell bold
ws["A1"].s = {
    font: {
        bold: true,
    }
};

// Add the worksheet to the workbook
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');

// Export the workbook to XLSX format
const wbout = XLSX.write(wb, { bookType: 'xlsx', type: 'buffer' });

// Convert the binary data to a Blob
const blob = new Blob([wbout], { type: 'application/vnd.ms-excel' });

// Download of the file using file-saver
saveAs(blob, 'example.xlsx');