如何使用 xlsx / SheetJS 使标题行加粗

基于我们之前的示例 如何使用 xlsx / SheetJS 使单元格加粗,以下代码示例将为第一行的每个单元格设置 {s: {font: {bold: true}}

此代码假设你知道列数(本例中为 header.length)。

在将单元格内容添加到工作表之后添加以下代码。

make_header_bold.ts
// 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;
}

Check out similar posts by category: JavaScript, Typescript