日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 前端技术 > vue >内容正文

vue

前端vue方法导出为xsml

發(fā)布時(shí)間:2024/3/13 vue 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 前端vue方法导出为xsml 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

首先引用xlsx
首先是導(dǎo)出方法

// 導(dǎo)出exportExcel() {// 格式化數(shù)據(jù)為二維數(shù)組this.exportData = this.formatTableData()// 設(shè)置表格數(shù)據(jù)const ws = XLSX.utils.aoa_to_sheet(this.exportData)// 新建一個(gè)工作簿const wb = XLSX.utils.book_new()// 設(shè)置表格樣式,!cols為列寬const options = { '!cols': [] }for (const key in this.tableLabel) {options['!cols'].push({ wpx: this.tableLabel[key] })}ws['!cols'] = options['!cols']// 將工作表添加到工作簿XLSX.utils.book_append_sheet(wb, ws, 'Sheet1')// 輸出工作表,由文件名決定的輸出格式const fileNamePrefix = this.unitTestCoverObj.applicationNameconst time = getFullTime(null, true).replace(/-/g, '')const fileName = `${fileNamePrefix}${time}.xlsx`XLSX.writeFile(wb, fileName)this.$message({type: 'success',message: '導(dǎo)出成功'})}

格式化數(shù)據(jù)為二維數(shù)組

// 數(shù)據(jù)格式為二維數(shù)組formatTableData() {const data = []let tableRef = nulltableRef = this.$refs.unitTestCoverTabledata.push(...this.unitTestCoverData)if (!tableRef) {console.error('找不到表格組件ref')return []}const array = []array[0] = []this.tableLabel = {}for (const obj of tableRef.columns) {if (obj.type === 'index') {array[0].push('序號(hào)')this.tableLabel['index'] = obj.width} else {array[0].push(obj.label)this.tableLabel[obj.property] = obj.width || obj.minWidth || obj.realWidth || 100}}data.forEach((item, index) => {const subArray = []for (const head of Object.keys(this.tableLabel)) {if (head === 'index') {subArray.push(index + 1)continue}if (item[head] !== undefined) {if (head === 'coverage' || head === 'branchCoverage') {subArray.push(`${item[head]}%`)} else {subArray.push(`${item[head]}`)}} else {subArray.push('')}}array.push(subArray)})console.log(array)return array}

console到控制臺(tái)看一眼是這樣的:
第一組對(duì)象為xsml表格第一排

總結(jié)

以上是生活随笔為你收集整理的前端vue方法导出为xsml的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。