当前位置:网站首页>js--------对象数组转换成二维数组(excel表格导出)
js--------对象数组转换成二维数组(excel表格导出)
2022-08-10 08:22:00 【cc&】
js方法实现
/**
* excel导出插件方法:转换导出的表格数据为二维数组
* @param {*} list 表格数据
* @param {*} exportHeader 导出表头(属性名)数组
* @returns
*/
export function transformTdata(list, exportHeader) {
const secondArray = []
list.forEach((item) => {
const item_array = []
for (const enKey in item) {
if (exportHeader.includes(enKey)) {
item_array.push(item[enKey])
}
}
secondArray.push(item_array)
})
return secondArray
}
excel导出具体实现
// 导出当前页数据
async exportTd() {
const excel = await import('@/vendor/Export2Excel')
// excel表示导入的模块对象
// 导出数据key对应关系
const headerShips = {
手机号: 'mobile',
姓名: 'username',
入职日期: 'timeOfEntry',
聘用形式: 'formOfEmployment',
工号: 'workNumber',
转正日期: 'correctionTime',
部门: 'departmentName'
} // 1. 表头
const header = Object.keys(headerShips)
// 2. 导出数据项
const exportHeader = Object.values(headerShips)
// 3. 表头对应数据(二维数组)
const data = transformTdata(this.employeeList, exportHeader)
data.forEach((item) => {
item[3] === 1 ? (item[3] = '正式') : item[3]
})
excel.export_json_to_excel({
// // 表头 必填
// header: ['姓名', '工资'],
// // 表头对应的具体数据 必填
// data: [
// ['刘备', 100],
// ['关羽', 500]
// ],
header,
data,
filename: 'excel-list', // 导出下载的文件名称
autoWidth: true, // 导出excel列宽度是否自适应
bookType: 'xlsx' // 导出生成的文件类型
})
},边栏推荐
- Johnson全源最短路
- 同步锁synchronized追本溯源
- 高性能短连接设计
- C# 获取PCI等设备的插槽位置信息
- 阿里云数据库 RDS SQL Server 版的服务器绑定域名www.cxsdkt.cn.的呢?
- 全连接神经网络结构图,神经网络示意图怎么画
- 人工神经网络模型的特点,人工神经网络模型定义
- 每日一题,二叉树中增加一行
- Using the color picker
- [Learn Rust together | Advanced articles | RMQTT library] RMQTT message server - installation and cluster configuration
猜你喜欢

MySQL设置初始密码—注意版本mysql-8.0.30
[Learn Rust together | Advanced articles | RMQTT library] RMQTT message server - installation and cluster configuration

进程管理(动态的)

StringUtils的具体操作

UGUI - Events, iTween Plugin

VS2013-debug assembly code-generate asm file-structure memory layout-function parameter stack-calling convention

神经网络的三种训练方法,神经网络训练全过程

二叉树 --- 堆

明明加了唯一索引,为什么还是产生重复数据?

明明加了唯一索引,为什么还是产生重复数据?
随机推荐
.NET-8. My Thought Notes
90. (cesium house) cesium height monitoring events
卷积神经网络卷积层公式,卷积神经网络运算公式
菜鸟、小白在autojs和冰狐智能辅助之间如何选择?
Introduction to the delta method
Guys, may I ask, the oraclecdc error report is not serialized, but I see that the source code does not inherit serialization, what is the reason?
Is the write performance of raid5 faster than raid10?
TensorFlow 2.9的零零碎碎(一)
iwemeta元宇宙:一个娃娃卖9999元,泡泡玛特认为一点也不贵
硬件工程师90天学习资料及笔记汇总20220730
Unity—UGUI控件
每日一题,数组字符串的匹配问题
NPU architecture and force analysis
推荐几个高质量的软件测试实战项目
深度剖析“八大排序”(上)_ 探寻一些不为人知的细节
人工神经网络工作原理,神经网络的工作原理
Using the color picker
Rust learning: 6.3_ Tuples of composite types
解决win10win7win8系统找不到指定的模块,注册不了大漠插件的问题
The probability distribution and its application