rodrigo.cantunes
rodrigo.cantunes

Reputation: 180

How to download files using Office Web Add In

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.

Upvotes: 4

Views: 2494

Answers (5)

mirik
mirik

Reputation: 457

As a solution you can open new window and pass there your file url to the backend:

window.open("https://yourbackend.com?fileurl="+encode(url)) 

The backend on its side should act as a proxy and return response with redirect. This way the Outlook desktop client will open a new tab in a browser and show/download there your file.

Upvotes: 2

Dalibor Grudenic
Dalibor Grudenic

Reputation: 505

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.

Upvotes: 4

rodrigo.cantunes
rodrigo.cantunes

Reputation: 180

The download library, worked pretty well.

Upvotes: 0

MSFT-Jipyua
MSFT-Jipyua

Reputation: 391

There is a document.getFileAsync() API which allows you to get all the slices of the file. For details, see here https://dev.office.com/reference/add-ins/shared/document.getfileasync

Upvotes: 0

Juan Balmori
Juan Balmori

Reputation: 5046

Pretty much what you would do with any web application to download files. i would expose that functionality in a dialog shown using our showdialog APIs and also make sure the domain from where you will download the files is in the app domains entry in the Add-in manifest.

Upvotes: -1

Related Questions