From dbc64c2256760cf654778295e569908ff71711b6 Mon Sep 17 00:00:00 2001 From: liuchunfeng Date: Fri, 15 Mar 2019 18:02:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feature=20=E5=A2=9E=E5=8A=A0=E5=A4=8D?= =?UTF-8?q?=E6=9D=82=E8=A1=A8=E5=A4=B4=E5=AF=BC=E5=87=BA=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/vendor/Export2Excel.js | 14 +++++++++++++ src/views/excel/exportExcel.vue | 36 +++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/vendor/Export2Excel.js b/src/vendor/Export2Excel.js index ba956dc1e70..d4223f35849 100644 --- a/src/vendor/Export2Excel.js +++ b/src/vendor/Export2Excel.js @@ -145,9 +145,11 @@ export function export_table_to_excel(id) { } export function export_json_to_excel({ + multiHeader, header, data, filename, + merges, autoWidth = true, bookType= 'xlsx' } = {}) { @@ -155,9 +157,21 @@ export function export_json_to_excel({ filename = filename || 'excel-list' data = [...data] data.unshift(header); + + for (let i = multiHeader.length-1; i > -1; i--) { + data.unshift(multiHeader[i]) + } + var ws_name = "SheetJS"; var wb = new Workbook(), ws = sheet_from_array_of_arrays(data); + + if (merges.length > 0) { + if (!ws['!merges']) ws['!merges'] = []; + merges.forEach(item => { + ws['!merges'].push(XLSX.utils.decode_range(item)) + }) + } if (autoWidth) { /*设置worksheet每列的最大宽度*/ diff --git a/src/views/excel/exportExcel.vue b/src/views/excel/exportExcel.vue index 551b89f85e7..1702d978157 100644 --- a/src/views/excel/exportExcel.vue +++ b/src/views/excel/exportExcel.vue @@ -18,20 +18,22 @@ {{ scope.$index }} - - - - - - - - + + + + + + + + + +