feature[Excel]: support export merged header export (#1718)

This commit is contained in:
小新
2019-03-17 16:36:09 +08:00
committed by 花裤衩
parent c963f56686
commit 763b31d915
2 changed files with 35 additions and 15 deletions

View File

@@ -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 => {