npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fe-export-excel

v1.0.6

Published

浏览器端生成和导出 Excel

Downloads

20

Readme

exportexcel

浏览器端生成和导出 Excel。(Browser-side generation and export of Excel)

Import and API

import { exportexcel, workbook, download } from "fe-export-excel";

// 创建并下载 Excel
exportexcel(workbookName, worksheetConfig);
// exportexcel(workbookName, [worksheetConfig1, worksheetConfig2]);

// 创建 Excel
const wb = workbook(worksheetConfig);
// const wb = workbook([worksheetConfig1, worksheetConfig2]);

// 下载 Excel
download(wb, workbookName);

Examples

const headerStyle = {
  alignment: { vertical: "middle", horizontal: "center" },
};

const data = [
  {
    date: "2020年08月26日",
    count1: "1234",
    number1: "1234",
    count2: "1234",
    number2: "1234",
    weekCount: "1234",
    weekAvg: "1234",
    ratio: "1234",
    count: "1234",
    avg: "1234",
    stock: "1",
  },
];

const worksheet = {
  // 一个 excel 是一个 workbook,里面的每个工作表是一个 worksheet
  sheetName: "sheet1",

  // 详细配置参考: https://github.com/exceljs/exceljs
  // properties: {},
  // pageSetup: {},
  // headerFooter: {},
  // views: {},
  // autoFilter: {},
  // columns: {},

  // 可选,统一给单元格设置样式
  // numFmt, font, alignment, border, fill
  cellStyle: {
    // border: {
    //   top: { style: "thin", color: { argb: "00000000" } },
    //   left: { style: "thin", color: { argb: "00000000" } },
    //   bottom: { style: "thin", color: { argb: "00000000" } },
    //   right: { style: "thin", color: { argb: "00000000" } },
    // },
    // font: {
    //   name: "Comic Sans MS",
    //   family: 4,
    //   size: 16,
    //   bold: true,
    // },
    // alignment: { vertical: "middle", horizontal: "center" },
    // fill: {
    //   type: "pattern",
    //   pattern: "darkVertical",
    //   fgColor: { argb: "FFFF0000" },
    // },
    // numFmt: "0.00%",
  },

  rows: [
    // 行内容(不区分表头行和数据行), 
    [
      // 列内容,对象,可以进行相关配置;没有特殊配置时,也可以直接传字符串或者数字
      // 为对象时候必填,value 当前单元格的值,字符串或者数字
      // 可选,start 当前单元格起始列,从 0 开始;如 start 位置和数组索引位置一致可以省略
      // 可选,rowspan 当前单元格跨多少行
      // 可选,colspan 当前单元格跨多少列
      // 可选,style 为当前单元格的样式,配置同 cellStyle
      { start: 0, rowspan: 2, value: "时间", style: headerStyle },
      { start: 1, colspan: 2, value: "生产", style: headerStyle },
      { start: 3, colspan: 2, value: "联合试转运", style: headerStyle },
      { start: 5, colspan: 5, value: "产量", style: headerStyle },
      { start: 10, rowspan: 2, value: "期末库存", style: headerStyle },
    ],
    [
      { start: 1, value: "处数", style: headerStyle },
      { start: 2, value: "产能(万吨/年)", style: headerStyle },
      { start: 3, value: "处数" },
      { start: 4, value: "产能(万吨/年)", style: headerStyle },
      { start: 5, value: "本周累计", style: headerStyle },
      { start: 6, value: "本周日均", style: headerStyle },
      { start: 7, value: "本周日均环比", style: headerStyle },
      { start: 8, value: "1月1日起累计", style: headerStyle },
      { start: 9, value: "1月1日起日均", style: headerStyle },
    ],
    ...data.map((x) => [
      x.date,
      x.count1,
      x.number1,
      x.count2,
      x.number2,
      x.weekCount,
      x.weekAvg,
      x.ratio,
      x.count,
      x.avg,
      x.stock,
    ]),
  ],
};

// 只有一个 worksheet 的时候可以直接传 worksheet
// exportExcel("测试", worksheet);
exportexcel("测试", [worksheet]);