1、下载依赖包
npm install -S file-saver xlsx
插件详细介绍
https://github.com/SheetJS/js-xlsx
https://github.com/eligrey/FileSaver.js
2、引用依赖包
import FileSaver from 'file-saver';
import XLSX from 'xlsx';
3、表格导出excel
html
<el-table id="out-table" :data="tableData">
<el-table-column prop="id" label="数据源编号">
<template scope="scope">
<span>{
{scope.row.id}}</span>
</template>
</el-table-column>
</el-table>
<el-button type="button" @click="exportFunc">质量问题报表</el-button>
js
exportFunc(e) {
// 从表生成工作簿对象
var wb = XLSX.utils.table_to_book(document.querySelector("#out-table"));
/

本文介绍了如何在Vue项目中使用xlsx和file-saver库来实现前端的Excel导入和导出功能。首先,通过npm安装这两个依赖包。接着,引入并使用它们,展示导出表格到Excel的JavaScript代码。对于导入Excel,文章提供了一个简单的代码片段作为备忘。

1149

被折叠的 条评论
为什么被折叠?



