Office.js Excel Online Failed to load resource: functions.json

Viewed 267

I developed an Excel Add-in using JavaScript API (office.js). Then, I'm using an Asp.Net MVC at the server-side. This works fine on excel desktop, but custom functions don't work in Excel on the web. When I inspect the task pane it shows these errors:

Access to XMLHttpRequest at 'https://www.xxxxxx.com.br/dist/functions.json' from origin 'https://excel.officeapps.live.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Failed to load resource: net::ERR_FAILED https://www.xxxxxx.com.br/dist/functions.json

In Excel on the Web, the task pane and the commands work fine. The CORS problem in functions.json is strange because this archive belongs to the dist folder.

I saw this document and modified the HTTP response headers but it doesn't work.

CORS

OBS: Everything is hosted at the same domain

Can you give me some direction?

1 Answers

You just need to make sure your webserver that's serving the add-in files returns Access-Control-Allow-Origin header with value * for all requests (or at least /functions.json request).


If you're using nginx to host the add-in files then add to config:

location / {
    add_header 'Access-Control-Allow-Origin' '*' always;
}

https://serverfault.com/a/979627/450717


If using apache to host the files then use the mod_headers module:

Header always set Access-Control-Allow-Origin "*"

https://stackoverflow.com/a/35566100/1053362


Related