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

v0.2.4

Published

A simple .xlsx file input/output lib based node-xlsx.

Downloads

2

Readme

xlsx-io

import! only support es6+ node environment

重要提示!仅仅支持es6及以上的node运行环境

xlsx-io是一个基于node-xlsx的简单的Excel工作簿(*.xlsx)格式文件的读取写入工具。支持javascript Object/Array类型的数据读取及写入。

XlsxBuilder


'use strict';

const XlsxBuilder = require('xlsx-io').XlsxBuilder;

// 创建XlsxBuilder对象
const builder = new XlsxBuilder();
// 以数组的形式添加数据
builder.addSheet({
    name: 'sheet1',
    columnsName: ['column1', 'column2', 'column3', 'column4'],
    data: [
        [1, 2, 3, 4],
        ['a', 'b', 'c', 'd'],
        [1, null, '', `\'`],
        [null, undefined, 1, 'a'],
    ],
    dataType: 'array'
});

// 以对象数组的形式添加数据

builder.addSheet({
    name: 'sheet2',
    columnsName: ['column1', 'column2', 'column3', 'column4'],
    data: [
        {
            column1: 1,
            column2: 2,
            column3: 3,
            column4: 4
        },
        {
            column1: 'a',
            column2: 'b',
            column3: 'c',
            column4: 'd'
        },
        {
            column1: 1,
            column2: null,
            column3: '',
            column4: `\'`
        },
        {
            column1: null,
            column2: undefined,
            column3: 1,
            column4: 'a'
        }
    ],
    dataType: 'object'
});

// 输出buffer

const bufResult = builder.output();

// 输出到文件

builder.output('result.xlsx');

XlsxParser

'use strict';

const XlsxParser = require('xlsx-io').XlsxParser;

// 创建XlsxBuilder对象
const parser = new XlsxParser('result.xlsx');
// 获取表名
const sheetNames = parser.SheetNames;
console.log(sheetNames);

// 获取指定表的列名(参数为表的序号)
const columnsName = parser.columnsName(0);
console.log(columnsName);

// 获取指定表的数据(每一行为一个数组)
const sheetRows = parser.sheetRows(0);
console.log(sheetRows);

// 获取指定表的数据(返回一个对象,result.status=true, result.data中每一行为一个对象)
const sheetMaps = parser.sheetMaps({
    sheet: 0,
    columnsName: ['column1', 'column2', 'column3', 'column4']
});
if(sheetMaps.status){
    console.log(sheetMaps.data);
}

// 获取指定表的数据(每一行为一个对象),如果columnsName中有表中不存在的列名,result.status=false. result.errors 里面是不存在的列名
const sheetMaps2 = parser.sheetMaps({
    sheet: 0,
    columnsName: ['column1', 'column2', 'column3', 'column4', 'not in sheet']
});
console.log(sheetMaps2);