当前位置:网站首页>将el-table原样导出为excel表格
将el-table原样导出为excel表格
2022-06-30 21:13:00 【bidepanm】
安装依赖
npm install --save xlsx file-saver
引入
import XLSX from 'xlsx';
import FileSaver from 'file-saver';
导出方法
exportExcel(excelName) {
//excelName --设置导出的excel名称
//report-table --对应的要导出的el-table的ref名称
try {
const $e = this.$refs['report-table'].$el;
// 如果表格加了fixed属性,则导出的文件会生产两份一样的数据,所以可在这里判断一下
let $table = $e.querySelector('.el-table__fixed');
if (!$table) {
$table = $e;
}
// 为了返回单元格原始字符串,设置{ raw: true }
const wb = XLSX.utils.table_to_book($table, { raw: true });
const wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' });
FileSaver.saveAs(
new Blob([wbout], { type: 'application/octet-stream' }),
`${excelName}.xlsx`,
);
} catch (e) {
if (typeof console !== 'undefined') console.error(e);
}
}
https://github.com/SheetJS/js-xlsx
https://github.com/eligrey/FileSaver.js
https://segmentfault.com/a/1190000022936812
边栏推荐
- 你我他是谁
- 《ClickHouse原理解析与应用实践》读书笔记(1)
- ArcMap|用字段计算器对不同类别的id赋值
- 判断js对象是否为空的方式
- 三个火枪手
- Four Misunderstandings of Internet Marketing
- Text recognition svtr paper interpretation
- 报错FileSystemException: /datas/nodes/0/indices/gtTXk-hnTgKhAcm-8n60Jw/1/index/.es_temp_file:结构需要清理
- 毕业五年,想当初若没有入行测试,我是否还会如这般焦虑
- 变异系数法matlab代码[通俗易懂]
猜你喜欢

CentOS - enable / disable Oracle

ArcGIS construction and release of simple road network data service and rest call test

阿里kube-eventer mysql sink简单使用记录

Qiao NPMS: search for NPM packages

关于,奇安信检测代码漏洞,XSS系列解决

Oracle 数据库表结构 Excel 导出

银行集体下架的智能投顾产品,为何成了“鸡肋”?

在线教育项目用户登录和注册

科研中遇到迷茫困惑如何向前一步?如何在科研中发挥女性优势?

1.微信小程序页面跳转方法总结;2. navigateTo堆栈到十层不跳转问题
随机推荐
在线教育项目用户登录和注册
Software engineering UML drawing
MySQL batch update
Go build server Foundation
一文读懂什么是MySQL索引下推(ICP)
Adobe-Photoshop(PS)-脚本开发-去除文件臃肿脚本
. NETCORE redis geo type
[grade evaluator] how to register a grade evaluator? How many passes?
Peking University ACM problems 1003:hangover
有趣网站汇总
Side sleep ha ha ha
给苏丹国安德森苏丹的撒过 d s g
Text recognition svtr paper interpretation
k个一组反转链表
减少嵌入式软件调试时间的三个技巧
coredns 修改upstream
Learning summary
Peking University ACM problems 1001:exposition
开源实习经验分享:openEuler软件包加固测试
Adobe Photoshop (PS) - script development - remove file bloated script