前端vue方法导出为xsml
生活随笔
收集整理的这篇文章主要介绍了
前端vue方法导出为xsml
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
首先引用xlsx
首先是导出方法
格式化数据为二维数组
// 数据格式为二维数组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('序号')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到控制台看一眼是这样的:
第一组对象为xsml表格第一排
总结
以上是生活随笔为你收集整理的前端vue方法导出为xsml的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: wcf教程-传递数据过大怎么配置?读取
- 下一篇: vue中如何清除echarts上次保留的