From 04b5222fcf0c8f24b3a577cf3a05fb57462982a5 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 11 八月 2020 09:18:27 +0800 Subject: [PATCH] 2020-08-11 --- src/tabviews/zshare/actionList/exceloutbutton/index.jsx | 70 ++++++++++++++++------------------ 1 files changed, 33 insertions(+), 37 deletions(-) diff --git a/src/tabviews/zshare/actionList/exceloutbutton/index.jsx b/src/tabviews/zshare/actionList/exceloutbutton/index.jsx index f49bcf5..1f4d6b4 100644 --- a/src/tabviews/zshare/actionList/exceloutbutton/index.jsx +++ b/src/tabviews/zshare/actionList/exceloutbutton/index.jsx @@ -378,54 +378,50 @@ */ exportExcel = (data) => { const { btn } = this.props - if (data && data.length > 0) { - try { - let _header = [] - let _topRow = {} - let colwidth = [] + + try { + let _header = [] + let _topRow = {} + let colwidth = [] - btn.verify.columns.forEach(col => { - if (!data[0].hasOwnProperty(col.Column)) return - if (_topRow[col.Column]) return + btn.verify.columns.forEach(col => { + if (_topRow[col.Column]) return - _header.push(col.Column) - _topRow[col.Column] = col.Text + _header.push(col.Column) + _topRow[col.Column] = col.Text - colwidth.push({width: col.Width}) + colwidth.push({width: col.Width || 20}) + }) + + let table = [] + + table.push(_topRow) + + data && data.forEach(item => { + let _row = {} + _header.forEach(field => { + _row[field] = item[field] }) - let table = [] + table.push(_row) + }) - table.push(_topRow) + const ws = XLSX.utils.json_to_sheet(table, {header: _header, skipHeader: true}) - data.forEach(item => { - let _row = {} - _header.forEach(field => { - _row[field] = item[field] - }) + ws['!cols'] = colwidth - table.push(_row) - }) + const wb = XLSX.utils.book_new() + XLSX.utils.book_append_sheet(wb, ws, 'Sheet1') - const ws = XLSX.utils.json_to_sheet(table, {header: _header, skipHeader: true}) + XLSX.writeFile(wb, this.state.excelName) - ws['!cols'] = colwidth - - const wb = XLSX.utils.book_new() - XLSX.utils.book_append_sheet(wb, ws, 'Sheet1') - - XLSX.writeFile(wb, this.state.excelName) - - if (btn.verify && btn.verify.enable === 'true' && btn.verify.script) { - this.execCustomScript() - } else { - this.execSuccess({ErrCode: 'S', ErrMesg: '瀵煎嚭鎴愬姛锛�'}) - } - } catch { - this.execError({ErrCode: 'N', message: 'Excel鐢熸垚澶辫触锛�'}) + if (btn.verify && btn.verify.enable === 'true' && btn.verify.script) { + this.execCustomScript() + } else { + this.execSuccess({ErrCode: 'S', ErrMesg: '瀵煎嚭鎴愬姛锛�'}) } - } else { - this.execError({ErrCode: 'N', message: '鏈煡璇㈠埌瀵煎嚭鏁版嵁锛�'}) + } catch { + this.execError({ErrCode: 'N', message: 'Excel鐢熸垚澶辫触锛�'}) } } -- Gitblit v1.8.0