From 149566b2e1a0154a75a50aef98febe046b728cdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9A=B4=E7=82=B3=E6=9E=97?= <15237758276@163.com> Date: Mon, 17 Feb 2025 16:31:44 +0800 Subject: [PATCH] no message --- wms-vue/src/components/duochaxun/RongQi.vue | 52 ++++++++++++--------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/wms-vue/src/components/duochaxun/RongQi.vue b/wms-vue/src/components/duochaxun/RongQi.vue index 5250c6a..70c7cb4 100644 --- a/wms-vue/src/components/duochaxun/RongQi.vue +++ b/wms-vue/src/components/duochaxun/RongQi.vue @@ -20,7 +20,7 @@ @@ -46,7 +46,7 @@ @@ -68,13 +68,13 @@ -
数据详情 +
数据详情 @@ -406,32 +406,38 @@ export default { this.exportToExcel(); }, // 表格数据写入excel,并导出为Excel文件 - exportToExcel(){ - /*const worksheet = XLSX.utils.json_to_sheet(this.tableData); - const workbook = XLSX.utils.book_new(); - XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1'); - XLSX.writeFile(workbook, 'table_data.xlsx');*/ - const XLSX = require('xlsx') - console.log('XLSX',XLSX,FileSaver) - // 使用 this.$nextTick 是在dom元素都渲染完成之后再执行 - this.$nextTick(function () { - // 设置导出的内容是否只做解析,不进行格式转换 false:要解析, true:不解析 - const xlsxParam = { raw: true } - const wb = XLSX.utils.table_to_book(document.querySelector('#educe-table'), xlsxParam) - // 导出excel文件名 - let fileName = '容器流通' + new Date().getTime() + '.xlsx' + exportToExcel() { + const XLSX = require('xlsx'); + const FileSaver = require('file-saver'); // 确保你已经安装了 file-saver 库 - const wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' }) + console.log('XLSX', XLSX, FileSaver); + + this.$nextTick(() => { + const workbook = XLSX.utils.book_new(); + + // 假设你有三个表格,分别对应三个不同的 ID + const tableIds = ['#educe-table1', '#educe-table2', '#educe-table3']; + const sheetNames = ['Sheet1', 'Sheet2', 'Sheet3']; + + tableIds.forEach((tableId, index) => { + const worksheet = XLSX.utils.table_to_sheet(document.querySelector(tableId), { raw: true }); + XLSX.utils.book_append_sheet(workbook, worksheet, sheetNames[index]); + }); + + // 导出excel文件名 + let fileName = '容器流通' + new Date().getTime() + '.xlsx'; + + const wbout = XLSX.write(workbook, { bookType: 'xlsx', bookSST: true, type: 'array' }); try { // 下载保存文件 - FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), fileName) + FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), fileName); } catch (e) { if (typeof console !== 'undefined') { - console.log(e, wbout) + console.log(e, wbout); } } - return wbout - }) + return wbout; + }); }, parseTime(time, cFormat) { //获取当前时间