Code Monkey home page Code Monkey logo

html2excel's Introduction

使用方式

npm i xlsx
        <button  @click="downloadFile" >导出EXCEL</button>
         <a ref="downloadBtn"></a>
// 不依赖Vue,但依赖ES6
import html2Excel from 'html2Excel'; 




export default{
    data:{
        list:[],
        outFile:null,
    },
    methods:{
                  getMsg(item){
                    let _item= item;
                    let info = {
                      '标题1':_item.text1,
                      '标题2':this.text2,
                      '标题3':_item.text3 ,
                    };
                    return info;
                  },
                  // 导出到excel
                  downloadFile: function() { // 点击导出按钮

         
                    let list = [];
                    this.list.forEach(item => {
                      list.push(this.getMsg(item));
                    });
                    let self = this;
                    html2Excel({
                      lists: list, // 需要转为excel的数据(需要自己提前处理成合适的格式)
                      title: '导出EXCEL', // excel的名称 格式为:XXXX-2018-02-12 16_56_22
                      input: this.outFile, // 触发下载的按钮,必须是a标签
                      cb() { // 触发下载后的回调

                      }
                    })
                  },
        },
        mounted(){
            this.outFile = this.$refs.downloadBtn;
        }

}

html2excel's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.