欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue中el-table前端如何導(dǎo)出excel數(shù)據(jù)表格

 更新時(shí)間:2024年07月15日 10:46:12   作者:~張小八~  
這篇文章主要介紹了vue中el-table前端如何導(dǎo)出excel數(shù)據(jù)表格,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下

一、el-table為正常時(shí),導(dǎo)出方法如下:

1.添加導(dǎo)出按鈕

        <el-button class="greenLinearbg dc"  size="small"  @click="webExportTotalExcel()" v-if="totalBillShow">導(dǎo)出</el-button>

2.導(dǎo)出方法

 // web導(dǎo)出匯總單excel
      webExportTotalExcel(){
        // 獲取表格數(shù)據(jù)
        //const tableData = this.userTotalList;
        const tableData = this.userTotalList.map(row => {  //創(chuàng)建一個(gè)新的數(shù)組,處理null值
          return Object.keys(row).reduce((acc, key) => {
            acc[key] = row[key] === null ? '' : row[key];
            return acc;
          }, {});
        });
        // 構(gòu)建 Excel 文件內(nèi)容
        let excelContent = `<html><head><meta charset="UTF-8"></head><body><table border="1">`;
        // 添加表頭
        excelContent += '<tr>';
        for (const column of this.$refs.tableRef.columns) {
          if (column.property) {
            excelContent += `<th>${column.label}</th>`;
          }
        }
        excelContent += '</tr>';
        // 添加表格數(shù)據(jù)
        for (const row of tableData) {
          excelContent += '<tr>';
          for (const column of this.$refs.tableRef.columns) {
            if (column.property) {
              excelContent += `<td>${row[column.property]}</td>`;
            }
          }
          excelContent += '</tr>';
        }
        // 構(gòu)建完整的 Excel 文件內(nèi)容
        excelContent += '</table></body></html>';
        // 創(chuàng)建 Blob 對(duì)象
        const blob = new Blob([excelContent], { type: 'application/vnd.ms-excel' });
        // 創(chuàng)建鏈接并觸發(fā)下載
        const link = document.createElement("a");
        link.href = URL.createObjectURL(blob);
        link.download = '匯總單.xlsx'; // 設(shè)置默認(rèn)文件名
        link.style.display = "none";
        document.body.appendChild(link);
        link.click();
        window.URL.revokeObjectURL(link.href);
      },

二、el-table中列為循環(huán)數(shù)據(jù)時(shí),如下圖所示:

在這里插入圖片描述

在這里插入圖片描述

導(dǎo)出方法如下:
1.導(dǎo)出按鈕:

<el-button class="greenLinearbg dc"  size="small"  @click="webExportHistoryExcel('','歷史賬單','el-table__fixed-right',0,'message')" v-if="historyBillShow">導(dǎo)出</el-button>

2.導(dǎo)出方法為:

  // web導(dǎo)出歷史賬單excel
      webExportHistoryExcel(id,excelName,className,number=0){
        const loading = this.$loading({
          lock: true,
          text: '數(shù)據(jù)導(dǎo)出中',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        const columns = this.$refs.message.columns,outputColumns=[];
        for(let i=0,len=columns.length;i<len;i++){
          if('label' in columns[i]){
            if('prop' in columns[i])
              outputColumns.push(columns[i].prop);
            else if('slot' in columns[i] && columns[i].slot!='action' && columns[i].label!='操作')
              outputColumns.push(columns[i].slot);
          }
        }
        if(this.$refs.message.selectRow=='all'){
          request({
            url:'/system/nonResidentYhzd/selectYhzdTable',
            method:'post',
            data:{pageNum:1,pageSize:this.queryParams.total}
          }).then(response => {
            ExportUtils.exportExcel(id,excelName,'',className,number,this.$refs.message.selectRow,response.rows,outputColumns);
            loading.close();
          });
        }
        else{
          ExportUtils.exportExcel(id,excelName,'',className,number,this.$refs.message.selectRow,this.$refs.message.selectList,outputColumns);
          loading.close();
        }
      },

到此這篇關(guān)于vue中el-table前端導(dǎo)出excel數(shù)據(jù)表格的文章就介紹到這了,更多相關(guān)vue el-table導(dǎo)出excel數(shù)據(jù)表格內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue3中ref與reactive的詳解與擴(kuò)展

    Vue3中ref與reactive的詳解與擴(kuò)展

    在vue3中對(duì)響應(yīng)式數(shù)據(jù)的聲明官方給出了ref()和reactive()這兩種方式,下面這篇文章主要給大家介紹了關(guān)于Vue3中ref與reactive的相關(guān)資料,需要的朋友可以參考下
    2021-06-06
  • 基于Vue實(shí)現(xiàn)手勢(shì)簽名

    基于Vue實(shí)現(xiàn)手勢(shì)簽名

    這篇文章主要為大家詳細(xì)介紹了基于Vue實(shí)現(xiàn)手勢(shì)簽名,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • 詳解Vue微信授權(quán)登錄前后端分離較為優(yōu)雅的解決方案

    詳解Vue微信授權(quán)登錄前后端分離較為優(yōu)雅的解決方案

    這篇文章主要介紹了詳解Vue微信授權(quán)登錄前后端分離較為優(yōu)雅的解決方案,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-06-06
  • vue 監(jiān)聽鍵盤回車事件詳解 @keyup.enter || @keyup.enter.native

    vue 監(jiān)聽鍵盤回車事件詳解 @keyup.enter || @keyup.enter.native

    今天小編就為大家分享一篇vue 監(jiān)聽鍵盤回車事件詳解 @keyup.enter || @keyup.enter.native,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08
  • Vue組件之單向數(shù)據(jù)流的解決方法

    Vue組件之單向數(shù)據(jù)流的解決方法

    這篇文章主要介紹了Vue組件之單向數(shù)據(jù)流的解決方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-11-11
  • Vue 修改網(wǎng)站圖標(biāo)的方法

    Vue 修改網(wǎng)站圖標(biāo)的方法

    這篇文章主要介紹了Vue 修改網(wǎng)站圖標(biāo)的方法,幫助大家更好的理解和使用vue框架,感興趣的朋友可以了解下
    2020-12-12
  • vue?指令與過(guò)濾器案例代碼

    vue?指令與過(guò)濾器案例代碼

    這篇文章主要介紹了vue?指令與過(guò)濾器,本文通過(guò)案例代碼給大家詳細(xì)講解,給大家講解的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-11-11
  • Vue CLI中模式與環(huán)境變量的深入詳解

    Vue CLI中模式與環(huán)境變量的深入詳解

    模式是 Vue CLI 項(xiàng)目中一個(gè)重要的概念,下面這篇文章主要給大家介紹了關(guān)于Vue CLI中模式與環(huán)境變量的相關(guān)資料,需要的朋友可以參考下
    2021-05-05
  • vue3 Element Plus中icon圖標(biāo)不顯示的解決方案

    vue3 Element Plus中icon圖標(biāo)不顯示的解決方案

    這篇文章主要介紹了vue3 Element Plus中icon圖標(biāo)不顯示的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • Vue+Vant實(shí)現(xiàn)頂部搜索欄

    Vue+Vant實(shí)現(xiàn)頂部搜索欄

    這篇文章主要為大家詳細(xì)介紹了Vue+Vant實(shí)現(xiàn)頂部搜索欄,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-06-06

最新評(píng)論