I want to make an Office add-in with angularjs and angularjs-ui-router:
<bt:Urls>
<bt:Url id="Contoso.Taskpane3.Url" DefaultValue="https://localhost:3000/addin/test" />
</bt:Urls>
The name of the module is app
, and the router is as follows:
.state('addinTest', {
url: '/addin/test',
tempalte: 'abc',
controller: 'TestCtrl',
resolve: {
loadMyCtrl: ['$ocLazyLoad', function ($ocLazyLoad) {
return $ocLazyLoad.load('https://appsforoffice.microsoft.com/lib/1/hosted/office.js');
}],
initOffice: ['loadMyCtrl', function (loadMyCtrl) {
Office.initialize = function (reason) {
$(document).ready(function () {
angular.element(document).ready(function () {
angular.bootstrap(document, ['app'])
})
});
}
return Promise.resolve(null)
}]
}
})
And the controller:
app.controller('TestCtrl', [function () {
function loadDataAndCreateChart() {
Excel.run(function (ctx) {
var sheet = ctx.workbook.worksheets.getActiveWorksheet();
sheet.getRange("A1").values = "Quarterly Sales Report";
return ctx.sync()
})
}
loadDataAndCreateChart()
}])
I would expect that loading the add-in writes Quarterly Sales Report
to A1
. However, I got the following error:
ReferenceError: Excel is not defined at loadDataAndCreateChart
Does anyone know what's wrong? Is it OK to initialize Office and use angular.bootstrap
like that?