首页 > 其他分享 >sheetjs style

sheetjs style

时间:2022-08-25 11:16:17浏览次数:56  
标签:XLSX style sheet utils sheetjs ws true

sheetjs导出excel,设置样式

https://github.com/gitbrent/xlsx-js-style

导入

<script src="./xlsx.bundle.js"></script>

demo

function download() {
    const wb = XLSX.utils.book_new()
    var ws = XLSX.utils.json_to_sheet([
    ], {header:["7月新华公司报结申请单"]});
    XLSX.utils.sheet_add_json(ws, [
      {A: '报结单号', D: '报结日期', E: '2022.07.22', I: 'MES_ID:', J: 'BJ-2022070021',
      L: '结算单位:', N: '江西新华新材料科技股份有限公司'}
    ], {skipHeader: true, origin: "A2", header: getA_Z()});
    ws['!merges'] = [XLSX.utils.decode_range('A1:U1')];
    ws['!merges'].push(XLSX.utils.decode_range('A2:B2'));
    ws['A1'].s = ws['A2']['s'] = {
      font: {
        name: '宋体',
        sz: 24,
        bold: true,
        color: { rgb: "FFFFAA00" }
      },
    }

    // 3、把工作表放到工作簿中
    XLSX.utils.book_append_sheet(wb, ws, 'sheet')
    console.log(ws)
    // 4、生成数据保存
    XLSX.writeFile(wb,"测试表格.xlsx",{
      cellStyles: true,
      bookType: 'xlsx'
    });
  }

  function getA_Z() {
    let a = 'A'.charCodeAt(0);
    let z = 'Z'.charCodeAt(0)
    let arr = [];
    for (; a <= z; a++) {
      arr.push(String.fromCharCode(a))
    }
    return arr;
  }

标签:XLSX,style,sheet,utils,sheetjs,ws,true
From: https://www.cnblogs.com/zhuxiang1633/p/16623572.html

相关文章