码迷,mamicode.com
首页 > 其他好文 > 详细

导出 Excel

时间:2018-09-18 11:08:06      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:base64   iter   time   邀请码   table   href   eal   element   cat   

this.dataSource.data 是个数组,每一个元素是 table 里的一行

思路就是:每个表格元素 列 后面加 ‘,‘ 每个表格元素 行后面加 ‘\n‘ 然后把数据拼接成字符串 targetTable

 1 exportTable() {
 2         let targetTable = ‘用户昵称,被邀请码,用户电话,实际邀请人数,总邀请人数,查询时的时间\n‘;
 3         for (let i = 0; i < this.length; i++) {
 4             targetTable += this.dataSource.data[i].nickname + ‘,‘;
 5             targetTable += this.dataSource.data[i].from_code + ‘,‘;
 6             targetTable += this.dataSource.data[i].phone + ‘,‘;
 7             targetTable += this.dataSource.data[i].real_invite_count + ‘,‘;
 8             targetTable += this.dataSource.data[i].total_invite_count + ‘,‘;
 9             targetTable += this.dataSource.data[i].now_time + ‘\n‘;
10         }
11 
12         targetTable = unescape(encodeURIComponent(targetTable));  // support chinese
13         if (this.length > 0) {
14             const a = document.createElement(‘a‘);
15             a.href = `data:application/vnd.ms-excel;base64,${btoa(targetTable)}`;
16             a.download = ‘inviteRank.csv‘;
17             a.click();
18         }
19     }

 

 

导出 Excel

标签:base64   iter   time   邀请码   table   href   eal   element   cat   

原文地址:https://www.cnblogs.com/luomi/p/9667192.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!