当前位置: 首页 > news >正文

使用exceljs导出部门-职位联动下拉框的excel


import { Workbook } from 'exceljs';///
const wb = new Workbook();
const ws = wb.addWorksheet('tb');
const dict2 = wb.addWorksheet('dict2');
const test = wb.addWorksheet('test');const test_data = [{post_name: '方案',department_name: '产品'
}, {post_name: '设计',department_name: '产品'
}, {post_name: 'js开发',department_name: '产品'
}, {post_name: '部门主管',department_name: '产品'
}];
const departments = Array.from(test_data.reduce((p, c) => {p.add(c.department_name);return p;
}, new Set()));
dict2.addRows(departments);ws.columns = [{ header: '员工编号', key: 'staff_no', width: 20 },	// A1{ header: '员工姓名', key: 'staff_name', width: 20 },	// B2{ header: '性别', key: 'sex', width: 20 },	// C3{ header: '部门名称', key: 'department_name', width: 20 },	// D4{ header: '岗位名称', key: 'post_name', width: 20 },	// E5{ header: '身份证号', key: 'id_no', width: 20 },	// 6{ header: '出生日期', key: 'birthday', width: 20 },	// 7{ header: '年龄', key: 'age', width: 20 },	// 8{ header: '联系电话', key: 'contact_number', width: 20 },	// 9{ header: '入职时间', key: 'staff_hiredate', width: 20 },	// 10{ header: '员工状态', key: 'staff_state', width: 20 }	// 11
];
///
new Array(5000).fill(0).forEach((_, idx) => {const row = idx + 2;// 渲染部门下拉框ws.getCell(row, 4).dataValidation = {type: 'list',formulae: [`=dict2!$C$2:$C${departments.length}`]};// 使用indirect函数添加引用, 渲染岗位ws.getCell(row, 5).dataValidation = {type: 'list',formulae: [`=INDIRECT(D${row})`]};
});// 添加名称管理器
const _data = test_data.reduce((p, c: any) => {if (!p.has(c.department_name)) {p.set(c.department_name, [c.post_name]);} else {const arr = p.get(c.department_name);arr.push(c.post_name);}return p;
}, new Map<string, string[]>());const department_names = Array.from(_data.keys());
const post_names = Array.from(_data.values());
test.addRows(post_names);test.eachRow(function (row, i) {const department_name = department_names[i - 1];console.log(department_name, i);row.eachCell(function (cell, colNumber) {cell.addName(department_name);});
});await wb.xlsx.writeFile('/home/feidao/Desktop/模板列表.xlsx');
return;
// const buff = await wb.xlsx.writeBuffer();
// return {
//  buff,
//  content_type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
//  attachment: '模板列表.xlsx'
// };


http://www.taodudu.cc/news/show-6102275.html

相关文章:

  • 【physx/wasm】在physx中添加自定义接口并重新编译wasm
  • excel---常用操作
  • Lora训练Windows[笔记]
  • linux基础指令讲解(ls、pwd、cd、touch、mkdir)
  • InnoDB 事务处理机制
  • 启明云端ESP32 C3 模组WT32C3通过 MQTT 连接 AWS
  • 导出excel此单元格中的数字为文本格式,或者其前面有撇号
  • linux查找所有可用的摄像头
  • 树莓派安装mplayer,并使用命令查看摄像头
  • vue获取摄像头
  • 谷歌浏览器获取摄像头
  • 树莓派4b摄像头使能
  • Opencv根据USB摄像头PID\VID号,获取对应摄像头索引
  • rk3588调试之imx415摄像头
  • 推荐用于环境识别的机器人摄像头
  • python opencv 摄像头_opencv python中摄像头参数的设置
  • 树莓派CSI摄像头使用
  • leetcode 968 监控摄像头
  • 根据硬件ID查看摄像头型号方案,可查任何一款摄像头芯片来源
  • android查看摄像头信息,获取Android设备上的详细的摄像头信息
  • python获取摄像头型号_python opencv设置摄像头分辨率以及各个参数的方法_python
  • python获取摄像头型号,python3.6 opencv获取摄像头代码
  • 我的世界服务器自动被踢怎么可以进去,我的世界中国版服务器中如何解决玩家作弊的简单方法...
  • VS2019+WDK10编写xp平台的驱动
  • Windows XP中手动安装驱动程序的方法
  • xp驱动和Win7驱动的区别
  • windows XP 驱动开发环境搭建
  • 戴尔1420装XP方法和驱动
  • window XP驱动开发(一)如何下载WDK
  • Window XP驱动开发(十) 驱动程序的基本结构
  • (14)[驱动开发]配置环境 VS2019 + WDK10 写 xp驱动
  • Window XP驱动开发(二) 环境搭建(VS2008+WDK+DDKWzard)及示例源码分析
  • DBA必知的170张Oracle常用动态性能表介绍
  • Linux-tcpdump
  • 【Linux】定时任务crontab和at命令详解
  • Java8 通关攻略