前端Excel自定义文件名导出

  • vue html代码

    下载
  • vue javascript代码

    exportExcel() {
        let excelData = [
            ['', '2020-10-16', '2020-10-17', '2020-10-18', '2020-10-19', '2020-10-20'],
            ['微服务调用次数', 123, 12, 123, 34, 423]
        ]
        let _text = ''
        excelData.forEach(rowData => {
            let rowStr = ''
            rowData.forEach(val => {
                rowStr += `${val + '/t'}`
            })
            rowStr = ''
            _text += rowStr
        })
        const sheetName = 'sheet'
        const uri = 'data:application/vnd.ms-excel;base64,';
        const template =
            `
            
                
                
            
            
                ${_text}
    ` this.$refs.exportExcel.href = uri + window.btoa(unescape(encodeURIComponent(template))); //定义导出的文件名 const filename = '导出的excel数据' this.$refs.exportExcel.download = filename this.$refs.exportExcel.click() }

你可能感兴趣的:(前端Excel自定义文件名导出)