• vue下载excel


    方法一:后台传入

    http({
                    url:'/statistical/exportPerson',
                    method:'post',
                    responseType:'blob',
                    params:{
                        name:this.name,
                        idCardNumber:this.idCardNumber,
                    }
                }).then(res => {
                    const fileName = '名单.xls'
                    let blob = new Blob([res.data], {
                        type: "application/octet-stream",
                    });
                    if ('download' in document.createElement('a')) {
                        const link = document.createElement('a')
                        link.download = fileName
                        link.style.display = 'none'
                        link.href = URL.createObjectURL(blob)
                        document.body.appendChild(link)
                        link.click() // 执行下载
                        URL.revokeObjectURL(link.href) // 释放url
                        document.body.removeChild(link) // 释放标签
                    } else { // 其他浏览器
                        navigator.msSaveBlob(blob, fileName)
                    }
                })
     
     
    方法二:前台做导出
    // 引入导出Excel表格依赖
    import FileSaver from "file-saver";
    import XLSX from "xlsx";
     
    exportExcel () {
                var xlsxParam = { raw: true } // 导出的内容只做解析,不进行格式转换,保证时间格式或者较长数字不会出现科学计数法。(这个很关键)
                var wb = XLSX.utils.table_to_book(document.querySelector('#exportTab'), xlsxParam)
                var wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' })
                try {
                    FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), '常见结果表.xlsx')
                } catch (e) {
                    if (typeof console !== 'undefined') {
                    console.log(e, wbout)
                    }
                }
                return wbout
            },
  • 相关阅读:
    nacos 命名空间
    Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column. To disable safe mode, toggle the option in Preferences
    gitee
    maven引入junit 4.12,项目import org.junit.Test 还是报错.
    gitflow
    202011
    idea 忽略显示不需要的文件
    服务熔断 & 降级区别
    各种微服务框架对比
    zookeeper not connected
  • 原文地址:https://www.cnblogs.com/brillant/p/16326504.html
Copyright © 2020-2023  润新知