Coder Social home page Coder Social logo

vue_excel_export's Introduction

vue_excel_export

Vue 导出表格内容至 Excel



1. 安装三个依赖包

  npm install -S file-saver
  npm install -S xlsx
  npm install -D script-loader

2. 在项目中创建一个文件夹(比如vendor,一般是在src目录下创建)

Blob.jsExport2Excel.js 这两个文件夹放到新建的文件夹内。

3. 在页面中使用

Export2Excel.js 暴露了两个接口 export_table_to_excelexport_json_to_excel, 我们常用 export_json_to_excel

handleDownload() {
      console.log("导出文件");
      require.ensure([], () => {
        const { export_json_to_excel } = require("@/vendor/Export2Excel");
        const tHeader = ["姓名", "年龄"];   // Excel表头内容
        const filterVal = ["name", "age"];  // 页面表格的表头字段
        const list = this.desserts;   // this.desserts 为页面中的表格内容
        const data = this.formatJson(filterVal, list);
        export_json_to_excel(tHeader, data, "列表excel");   // 第三个参数为导出下载下来的Excel的名字
      });
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]));
    }
  }

vue_excel_export's People

Contributors

censek avatar

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.