Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download files using Office Web Add In

Tags:

office-js

As long as there are no way to 'Load' an Excel template in the client's Workbook using Javascript API for office, Is it possible to download the file through the browser's Add In? So the user can manually open it.

like image 660
rodrigo.cantunes Avatar asked Oct 24 '25 03:10

rodrigo.cantunes


1 Answers

You could do something like:

    saveFileToDesktop(blob, fileName) {
        if (window.navigator.msSaveOrOpenBlob) { // IE only
            window.navigator.msSaveOrOpenBlob(blob, fileName);
        } else {
            const link = document.createElement('a');
            link.href = window.URL.createObjectURL(blob);
            link.download = fileName;
            link.click();
        }
    }

This was working for me in the following combinations:

Client Windows Office(Excel, PowerPoint) & IE (because that is used in the taskpane)

Client Office Online(Excel, PowerPoint) & IE, Chrome, Safari, Firefox

not Working in:

Client Mac Office(Excel, PowerPoint) & Safari (because that is used in the taskpane)

It seems that download goes ok but I was not able to get to the file even tried changing preferences File download location: Ask for each download etc. but was not able to get it working.

like image 119
Dalibor Grudenic Avatar answered Oct 27 '25 01:10

Dalibor Grudenic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!