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-saver

v1.0.7

Published

A xlsx file saver base on JSXlsxCore,can use in node or browser.

Downloads

9

Readme

JSXlsxSaver

A xlsx file saver base on JSXlsxCore for node or browser.

基于JSXlsxCore(git/npm)实现的生成微软Office Excel xlsx文件格式的库。可以在node或者现代浏览器中使用。

本代码使用了jszip(npm)用于生成zip文件(xlsx本质上是一个zip文件);

如果要在浏览器在使用,推荐使用file-savernpm)来保存文件到本地。jszip中已经包含了这个文件(./vendor/FileSaver.js)

use in node

shell:

npm i xlsx-saver

js:

const XlsxCore = require('js-xlsx-core');
require('xlsx-saver');
const {
    Book,
    HorizontalAlignment,
    VerticalAlignment
} = XlsxCore;
var book = new Book();
var sheet = book.CreateSheet("第一页");
sheet.AddText('一个普通文本', 0, 0);
//...
//get buffer,you can send to http respone,or save to localfile
var buffer = await book.SaveAsBuffer();
//save to localfile
fs.writeFileSync('./out.xlsx', buffer);

use in browser

shell:

npm i xlsx-saver file-saver

html:

<script src="node_modules/jszip/dist/jszip.js"></script>
<script src="node_modules/jszip/vendor/FileSaver.js"></script>
<script src="node_modules/js-xlsx-core/xlsxcore.js"></script>
<script src="node_modules/xlsx-saver/xlsxsaver.js"></script>

js:

var test = async () => {
    const {
        Book,
        Sheet,
        Cell,
        ShareString,
        CellStyle,
        CellAlignment,
        NumberFormat,
        Image,
        ImageOption,
        HorizontalAlignment,
        VerticalAlignment
    } = XlsxCore;
    var book = new Book();
    var sheet = book.CreateSheet("第一页");
    sheet.AddText('一个普通文本', 0, 0);
    //...
    var bolb = await book.SaveAsBolb();
    // see FileSaver.js
    saveAs(bolb, "test.xlsx");
};

test();

support 支持的操作

  • 可在单元格中存放字符串、数字和图片。(时间类型暂时不支持,请使用字符串或数字存储。
  • 设置单元格字体样式:字体名称、字号、文字颜色、是否粗体、是否斜体、是否下划线;
  • 设置单元格纯颜色填充;
  • 设置单元格超链接;
  • 设置单元格水平垂直对齐方式;
  • 设置单元格是否支持换行;
  • 合并单元格;
  • 设置默认字体样式、默认行高、默认列宽;
  • 设置指定行的高度(行高所使用单位为磅,1厘米=28.6磅);
  • 设置指定列的宽度(列宽使用单位为1/10英寸,既1个单位为2.54毫米);
  • 设置单元格内图片大小(图片大小不能超过单元格,所以如果要设置比较大的图片,请设置合适的单元格大小);
  • 设置单元格中数字的显示格式,如百分比,千分符等等,具体的格式码可以参照微软文档
  • 通过共享文本共享字体共享填充共享样式共享格式码共享图片来达到一处定义多处使用,可以大大减少最终的文件体积。

best practice 最佳实践

  • 查看Demo获得更多使用方式;
  • 在xlsx中,当你有一个文本需要在多个单元格中显示时,可以使用Book.prototype.CreateShareString()获得一个共享文本,多处使用时对文件体积的影响微乎其微。可以在Demo中运行node shareStringDemo.js查看两个输出文件的大小进行比较;
  • 不要修改任何下划线开头的变量,会造成不可预估的错误。