当前位置:网站首页>将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
边栏推荐
- 双立体柱状图/双y轴
- 科研中遇到迷茫困惑如何向前一步?如何在科研中发挥女性优势?
- ca i啊几次哦啊句iu家哦
- 企业保护 API 安全迫在眉睫
- Adobe Photoshop (PS) - script development - remove file bloated script
- Peking University ACM problems 1001:exposition
- Gartner聚焦中国低代码发展 UniPro如何践行“差异化”
- stacking集成模型预测回归问题
- To the Sultanate of Anderson
- Deflection lock / light lock / heavy lock lock is healthier. How to complete locking and unlocking
猜你喜欢

Why have the intelligent investment advisory products collectively taken off the shelves of banks become "chicken ribs"?

Software engineering UML drawing

uniapp-路由uni-simple-router

Four Misunderstandings of Internet Marketing
![翻转链表II[翻转链表3种方式+dummyHead/头插法/尾插法]](/img/a8/6472e2051a295f5e42a88d64199517.png)
翻转链表II[翻转链表3种方式+dummyHead/头插法/尾插法]
Testing media cache

ICML2022 | 序列决策的效用理论

【无标题】

ArcGIS构建发布简单路网Network数据服务及Rest调用测试

3Ds Max 精模obj模型导入ArcGIS Pro (二)要点补充
随机推荐
oprator-1初识oprator
Markdown notes concise tutorial
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could
. NETCORE redis geo type
MySQL batch update
等级测评是什么意思?工作流程包含哪些?
有趣插件汇总
ClickHouse distributed表引擎
Peking University ACM problems 1005:i think I need a houseboat
Who are you and I
Adobe-Photoshop(PS)-脚本开发-去除文件臃肿脚本
19.04 distributor
关于,奇安信检测代码漏洞,XSS系列解决
个人开发的渗透测试工具Satania
在线教育项目用户登录和注册
What about degradation of text generation model? Simctg tells you the answer
Peking University ACM problems 1004:financial management
数字货币:影响深远的创新
Learning summary
What does grade evaluation mean? What is included in the workflow?