自学内容网 自学内容网

前端导出xlsx,并且带样式

xlsx-js-style | xlsx-js-style homepage (gitbrent.github.io)

import { utils, writeFile } from 'xlsx-js-style';
const tableEl = document.getElementById("export-table");
const workbook = utils.table_to_book(tableEl);

worksheet[i].t = "s";
worksheet[i].s = {
  s: {
    font: {
      name: "宋体",
      bold: true,
    },
    alignment: {
      horizontal: "center",
      vertical: "center",
      wrapText: true,
    },
    border: {
      top: { style: "thin", color: { rgb: "000000" } },
      bottom: { style: "thin", color: { rgb: "000000" } },
      left: { style: "thin", color: { rgb: "000000" } },
      right: { style: "thin", color: { rgb: "000000" } },
    },
    fill: {
      fgColor: { rgb: "909399" },
    },
  },
};


const worksheet = workbook?.Sheets?.Sheet1;
workbook.SheetNames = [sheetName];
workbook.Sheets[sheetName] = worksheet;
const innerHTML = document.getElementById("export-html").innerHTML;
utils.sheet_add_aoa(worksheet, [[innerHTML]], { origin: -1 });
writeFile(workbook, '名称.xlsx');

原文地址:https://blog.csdn.net/qq_19689967/article/details/142247294

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!