none
Office web add-ins - Download file stopped working after Excel upgraded RRS feed

  • Question

  • I had the office add-in (Excel add-ins) with a feature of downloading a string as a file. It worked fine before but stopped working with the error "Access Denied" or "Resource 'blob:https://....' not allowed to load" after a recent Excel2016 or windows update.

    I think the problem is caused by Microsoft started using Microsoft Edge to run the script from Excel2016 version 16.0.11629. Before it was using IE 11.

    The documentation of the browser used by office add-in: https://docs.microsoft.com/en-us/office/dev/add-ins/concepts/browsers-used-by-office-web-add-ins.

    I also tested with an old Excel 2016 the add-in still worked.

    Much appreciate if anyone can provide any solution, from code side or from security setting side(we suspect this is related to some security settings).

    ----- The add-in was developed using TypeScript

    /**
     * Generate the download link and download the file using the link. 
     * @param filename
     * @param text
     */
    export function download(filename: string, text: string) {
    
        const blob: Blob = new Blob([text], { type: 'text/csv,charset=UTF-8' });
    
        if (window.navigator.msSaveOrOpenBlob) {
            navigator.msSaveBlob(blob, filename);  //Add-in does not use this
        } else {
            //Add-in uses this
            const downloader = buildDownloader(filename, blob);
            document.body.appendChild(downloader);
            downloader.click();
            document.body.removeChild(downloader);
        }
    }
    
    export function buildDownloader(filename: string, blob: Blob): HTMLElement {
        const downloader = document.createElement('a');
        downloader.setAttribute('download', filename);
        downloader.setAttribute('href', window.URL.createObjectURL(blob));
        downloader.style.display = 'none';
        return downloader;
    }

    The download function should show windows dialog to ask to save or open the file. But now I got the access denied error.

    Lots of post/articles suggested that if Microsoft edge I should use 'msSaveOrOpenBlob' or 'msSaveBlob', but all of these two did not work with the error "Object doesn't support property or method 'msSaveOrOpenBlob'".

    I am not sure if the Edge used by add-in is a bit different from the application Edge.

    Thursday, September 5, 2019 3:20 AM

All replies

  • Hello!

    I faced this problem a couple days ago too and I came up to solve it by running VBA macro from addin. Please see whole workaround on stackoverflow: https:// stackoverflow.com/questions/57999868/is-there-is-a-way-to-insert-macro-to-worksheet-from-excel-addin

    I used the solution above to run macro which takes JSON from excel cells (the method how it work described in workaround) and just save it in needed format. A bit ugly, but it worked..


    • Edited by Arenukvern Friday, September 20, 2019 5:57 AM
    Friday, September 20, 2019 5:56 AM
  • Thanks Arenukvern. But we don't want to use macro as we also need to run the add-ins with office online sometime. Thanks though.
    Thursday, December 12, 2019 9:12 PM