RequestContext
Introduced in 2014 March for Office 2016.
The RequestContext object facilitates requests to the Office application.
This uses application specific APIs.
Because the Add-in and the Office application run in two different processes, request context is required to get access to the Office application from the add-in.
The JavaScript object declared is a proxy object for the real object until the add-in and Office application are synchronized.
A request context is created as shown and this object has two methods.
var context = new Excel.RequestContext();
context.sync - (Previously executeAsync when in preview). Submits the request queue to the office application and returns a promise object, which can be used for chaining further actions
Nested Syntax
Excel.run(function (context) {
return context.sync()
.then(function () {
return context.sync()
.then(function () {
return context.sync()
Invoke Chaining Syntax
This first chaining layout requires you to return 'context.sync()' multiple times.
Excel.run(function (context) {
return context.sync()
.then(function () {
return context.sync();
})
.then(function () {
return context.sync();
Reference Chaining Syntax
This second chaining layout only requires you to have one return statement.
Excel.run(function (context) {
return context.sync()
.then(function () {
.then(context.sync)
.then(function () {
.then(context.sync)
Async Await Syntax
Excel.run(async (context) => {
await context.sync();
await context.sync();
await context.sync();
© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited TopPrevNext