Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

saveAsFile does not exists #1

Open
lucasteles opened this issue May 16, 2019 · 3 comments
Open

saveAsFile does not exists #1

lucasteles opened this issue May 16, 2019 · 3 comments

Comments

@lucasteles
Copy link

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?

@Selmirrrrr
Copy link

Selmirrrrr commented Jun 4, 2019

Hello @lucasteles,

@danroth27 implemented an extension as shown here

@lucasteles
Copy link
Author

@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

@cartsp
Copy link

cartsp commented Dec 21, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants