前端base64转换成excel

baseToExcel(baseStr, fileName) {
        var raw = window.atob(baseStr);
        var uInt8Array = new Uint8Array(raw.length);
        for (var i = 0; i < raw.length; i++) {
            uInt8Array[i] = raw.charCodeAt(i);
        }

        const link = document.createElement("a");
        const blob = new Blob([uInt8Array], {
            type: 'application/vnd.ms-excel'
        })

        link.style.display = 'none';
        link.href = URL.createObjectURL(blob);
        link.setAttribute('download', fileName);

        document.body.appendChild(link)
        link.click()
        document.body.removeChild(link)
    }
posted @ 2024-03-28 17:18  亲爱的阿道君  阅读(177)  评论(0编辑  收藏  举报