From 3d973f7ddda4ff9aa74d7830e7da0c530d1fb713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=96=B0?= Date: Sun, 17 Mar 2019 16:36:09 +0800 Subject: [PATCH] feature[Excel]: support export merged header export (#1718) --- 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 ba956dc1..3fda4465 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,10 +157,22 @@ export function export_json_to_excel({ filename = filename || 'excel-list' data = [...data] data.unshift(header); + + for (let header of multiHeader) { + data.unshift(header) + } + 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每列的最大宽度*/ const colWidth = data.map(row => row.map(val => { diff --git a/src/views/excel/exportExcel.vue b/src/views/excel/exportExcel.vue index 0ef696e2..8e969386 100644 --- a/src/views/excel/exportExcel.vue +++ b/src/views/excel/exportExcel.vue @@ -19,20 +19,22 @@ {{ scope.$index }} - - - - - - - - + + + + + + + + + +