Search code examples
exceloffice-addinscustomtaskpane

Excel Task Pane add-in to show content from external source


I am trying to build an Excel/Word task pane add-in that should show content from our site. The content/data is passed in XML format.

What I have tried to do is the following:

Office.initialize = function (reason) {
    $(document).ready(function () {
        app.initialize();

        $.support.cors = true;

        var data = '';

        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            url: 'http://addons.mysite.com/excel-taskpane-data.php',
            data: data,
            dataType: "json",
            success: onQuerySuccess,
            error: onQueryError
        });

        function onQuerySuccess(res, statusText) {
            console.log('success!!' + res.statusText);
        }
        function onQueryError(res, statusText){
            console.log('failed!!' + res.statusText);
        }

  });

};

As you can understand from the code above I was just checking if connection could be made to the external source, but I am getting "Access Denied" in the console.

I am not really sure how should I request data from an external source and whether it is possible at all?

Please help


Solution

  • You mentioned 'external' so I bet http://addons.mysite.com/ is not the domain that serves your web add-in. To make it work you have to check several things.

    1. Serving with Https. As written by Michael make sure you use https. Mixed content (mixing of http and https) is blocked by most server and Office web add-ins can only be served with https.
    2. Make sur your PHP web api supports CORS. I am no PHP expert so here is a small link
    3. Try to specify https://addons.mysite.com as AppDomain The sandboxed iFrame allow only request and navigation on the same domain (the one that you use to serve you web-addin). But you can specify some exceptions see here. It works with navigation and I am not sure it works with XHR...
    4. If step 3 did not work try to use JSON/P techniques as described here JSON/P with Office add-ins