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

export-excel-xls

v1.0.1

Published

纯js导出excel,支持一个文件多个sheet,支持设置单元格样式

Downloads

6

Readme

excel导出 支持一张excel中包含多个sheet

Installation

npm install export-excel-xls --save-dev

Usage

import Excel from  'export-excel-xls'

1. 构建实例

    //构建excel实例对象
    let excel=new Excel();

    //此处设置所有的sheet中公用的表头
    let excel=new Excel({columns:[{title:'姓名',key:'name'},{title:'年龄',key:'age'}]});

2. 添加sheet

    //添加sheet ,并且返回当前sheet实例
    let sheet=excel.addSheet();

    //sheet中设置columns,仅对当前表格生效
    excel.addSheet({columns:[{title:'姓名',key:'name'}]});

    // hasHeader=false不显示表头, 默认值为true
    excel.addSheet({hasHeader:false});

3.添加行数据

    sheet.addRow({id:1,name:'张三',age:10});
    let row=sheet.addRow({id:1,name:'李四',age:8});
    let row2=sheet.addRow({id:3,name:'王五',age:9});
    sheet.addRow({id:3,name:'王五',age:9});
    sheet.addRow({id:3,name:'王五',age:9});
    sheet.addRow({id:3,name:'王五',age:9});

4.合并单元格

    //通过excel索引合并, A2开始,A3结束
    sheet.megerCell('A2' ,'A3');
    //通过自定义key , age列第二行到age列第三行
    sheet.megerCell('age2','age3');

    //行位置也可以通过row对象获取
    row.rowIndex

4.方法和样式

    //注意,所有的属性值,首字母必须大写。 比如:Right,Left,Center...
    //设置背景
    let cell=row.getCell('B2');
    cell.background="#8497B0"

    //设置字体
    cell.Font={
        Name:'宋体', //字体名称
        Color:"#ff4200", //颜色
        Bold:true, //是否加粗
        Size:20 //字体大小
    }
    //设置对齐方式
    cell.FoAlignmentnt={
        Horizontal:'Right',  //文字水平居中
        Vertical:"Center",//文字垂直居中
    }
    //循环设置
    row2.eachCells(function(el){
        el.Alignment.Horizontal="Right";  //文字水平居中
        el.Alignment.Vertical="Center";  //文字垂直居中
    
    });

5.导出

    excel.saveToExcel('demo.xls');
    //不写名称也会自动生成文件名
    excel.saveToExcel();