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

xlsx-style-node

v1.0.1

Published

node 生成xlsx 并且生成样式

Downloads

249

Readme

Node XLSX

此 api 是通过 node-xlsx 、xlsx-style、xlsx 三个 npm 组合使用的,来弥补 node-xlsx 不能设置颜色的问题,参数格式按照 node-xlsx 方式使用,设置样式参数按照 xlsx-style。

注意: 存在缺陷 设置不了行高(待完善)

按照

npm i xlsx-style-node

使用

在 js 中使用 const xlsx = require("xlsx-style-node").default; 在 ts 中使用 import * as xlsx from 'xlsx-style-node';

const fs = require("fs");
const data: any = [
  ["导表时间:2021-05-27 15:36:28"],
  ["用户Id: 288884"],
  ["用户名:test"],
  [],
  ["对账公式:"],
  ["期末余额=期初余额+入金-出金"],
  [],
  ["币种:USD"],
  [
    "*期初余额指本月度1号0点0分0秒余额",
    null,
    null,
    "*期末余额指本月度最后一天23点59分59秒余额",
  ],
  [
    "期初余额(总计)",
    "10000.01",
    null,
    "期末余额(总计)",
    "20000.01",
    null,
    "入金(总计)",
    "20000",
    null,
    "出金(总计)",
    "10000",
  ],
  [
    "账户余额",
    "8000",
    null,
    "账户余额",
    "18000",
    null,
    "账户充值",
    "19000",
    null,
    "账户转出",
    "9000",
  ],
  [
    "储值卡总可用余额",
    "99",
    null,
    "储值卡总可用余额",
    "3232",
    null,
    "账户转入",
    "999",
    null,
    "账户充值手续费",
    "000",
  ],
  [
    "额度卡(预算)总可用余额",
    "99",
    null,
    "额度卡(预算)总可用余额",
    "33",
    null,
    "储值卡转入",
    "44",
    null,
    "储值卡转出",
    "500",
  ],
  [
    null,
    null,
    null,
    null,
    null,
    null,
    "储值卡退款",
    "22",
    null,
    "储值卡消费(已完成)",
    "111",
  ],
  [
    null,
    null,
    null,
    null,
    null,
    null,
    "额度卡转入",
    "22",
    null,
    "储值卡消费(处理中)",
    "111",
  ],
  [
    null,
    null,
    null,
    null,
    null,
    null,
    "额度卡退款",
    "22",
    null,
    "储值卡退款手续费",
    "111",
  ],
  [null, null, null, null, null, null, null, null, null, "额度卡转出", "11"],
  [
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    "额度卡消费(已完成)",
    "11",
  ],
  [
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    "额度卡消费(处理中)",
    "11",
  ],
  [
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    "额度卡退款手续费",
    "11",
  ],
  [null, null, null, null, null, null, null, null, null, "开卡费", "11"],
];

// 设置样式
for (const index in data) {
  if (Number(index) < 5) continue;
  if (index === "7") continue; // 第八行不处理
  if (!data[index].length) continue;
  for (const index2 in data[index]) {
    if (!data[index][index2]) continue;
    const content = data[index][index2];
    if (index === "5") {
      data[index][index2] = {
        v: content,
        s: {
          font: {
            size: 24,
            bold: true, // 加粗
          },
        },
      };
    } else {
      data[index][index2] = {
        v: content,
        s: {
          alignment: {
            vertical: "center",
            horizontal: "center",
          },
          font: {
            size: 24,
            ...(index === "8" && { color: { rgb: "ff280c" } }), // 设置颜色
            ...(index === "9" && { bold: true }), // 字体加粗
          },
        },
      };
    }
  }
}

// 单元格宽度
const options = {
  "!cols": [
    { wpx: 260 },
    { wpx: 80 },
    { wpx: 30 },
    { wpx: 300 },
    { wpx: 80 },
    { wpx: 30 },
    { wpx: 160 },
    { wpx: 80 },
    { wpx: 30 },
    { wpx: 170 },
    { wpx: 80 },
  ],
};

const buffer = xlsx.build([{ name: "mySheetName", data: data, options }]);
fs.writeFileSync("test1.xlsx", buffer);

文档

node-xlsx