BlazorExcelSpreadsheet icon indicating copy to clipboard operation
BlazorExcelSpreadsheet copied to clipboard

saveAsFile does not exists

Open lucasteles opened this issue 6 years ago • 3 comments

Hi, iam trying you spreadsheet blazor sample, but iam getting an error on browser because of saveAsFile, its not exist in my version of Insider Edge, how do you make it work?

lucasteles avatar May 16 '19 17:05 lucasteles

Hello @lucasteles,

@danroth27 implemented an extension as shown here

Selmirrrrr avatar Jun 04 '19 13:06 Selmirrrrr

@Selmirrrrr the problem is the saveAsFile function does not exist in any browser yet, i have to use a polyfill for this saveAs and implement the saveAsFile for my own

https://github.com/lucasteles/BlazorExcelSpreadsheet/tree/master/GridDemo/wwwroot

lucasteles avatar Jun 05 '19 17:06 lucasteles

function saveAsFile(filename, bytesBase64) {
    if (window.navigator && window.navigator.msSaveOrOpenBlob) { // Needed for Edge
        var byteCharacters = atob(bytesBase64);
        var byteNumbers = new Array(byteCharacters.length);
        for (var i = 0; i < byteCharacters.length; i++) {
            byteNumbers[i] = byteCharacters.charCodeAt(i);
        }
        var byteArray = new Uint8Array(byteNumbers);
        var newBlob = new Blob([byteArray], { type: "application/octet-stream" })
        window.navigator.msSaveOrOpenBlob(newBlob, filename); 
    } else {
        var link = document.createElement('a');
        link.download = filename;
        link.href = "data:application/octet-stream;base64," + bytesBase64;
        document.body.appendChild(link); // Needed for Firefox
        link.click();
        document.body.removeChild(link);
    }
}

Is what I changed saveas to, to make it work with edge

cartsp avatar Dec 21 '19 20:12 cartsp