If you are porting an Apps Script add-on to an Office add-in, you may find you’ll be dealing with competing load methods if you are using google.load to bring in some google APIS. Office Add-ins like to have the Office framework loaded first, and google.load doesn’t work inside that.
It’s easy enough to tackle that using Promises. Here’s my Office app, loading both the Office framework and google.load. The onloadcallback for google.load resolves a Promise, which is waited for inside the Office.initialize function. That way, I know both frameworks have loaded and initialized before continuing.
(function () {
// each initialize fights with each other so do them separately and check theyve completed
var goo = new Promise(function (resolve,reject){
google.load('visualization', '1.1', { 'packages': ['sankey'] });
google.setOnLoadCallback(function () {
resolve();
});
});
Office.initialize = function (reason) {
// also need the google stuff to have loaded
goo.then(function() {
Server.initialize();
App.initialize();
Process.initialize().then(function () {
// set any listeners
Home.initialize();
// chaneg the polling behavior for Office
Server.pollingBehavior();
// watch for changes
Client.start();
});
})
.catch(function(err) {
throw err;
});
};
})();
The code for this on github.
Subpages
- Chord Snip
- Debugging Office JavaScript API add-ins
- Dicers
- Dicers Pro and advanced features
- Measuring round trip and execution times from add-ons
- Merging slide templates with tabular data
- Office Add-ins – first attempt
- Plotting maps with overlays Sheets add-on starter
- Promise implementation for Apps Script Stripe payments
- Repeatable add-on settings layouts and style
- Sheets API – Developer Metadata
- SlidesMerge add-on
- Unpicking the Google Picker
- Watching for changes in an Office add-in
- When test add-ons doesn’t work
- Polyfill for Apps Script properties service for the Office JavaScript API
- Sankey Snip