The Excel.run batch function must return a context.sync().
Every .then must either be fully synchronous or return a promise.
Excel.run(function(context) { batch })
The context is sometimes abbreviated to "ctx".
This executes a batch script that performs actions on the Excel object model.
The advantage of batching requests in Excel.run() is that when the promise is resolved, any tracked range objects that were allocated during the execution will be automatically released.


This example has been put together for illustration purposes only.
This code writes some numbers into cells "A1:B6" and then displays some of these numbers in the console window.
SS - cells
SS - console

JavaScript Sample

await Excel.run (async (context) => { 
    var sheet1 = context.workbook.worksheets.getActiveWorksheet();
    var range1 = sheet1.getRange("A1:B6");
    var mynumbers = [ [5, 10], [15, 20], [25, 30], [35, 40], [45, 50], [55, 60] ];
    range1.values = mynumbers;
    var range2 = sheet1.getRange("A1:B2");
    await context.sync()

    var cellvalue1 = range2.values[0][0];
    var range4 = sheet1.getRange("A3:B4");
    range5 = await context.sync(range4);

    var cellvalue2 = range5.values[0][0];
    var range6 = sheet1.getRange("A5:B6");
    range7 = await context.sync(range6);

    var cellvalue3 = range7.values[0][0];
    await context.sync();

}).then(function () { console.log("Finished");
}).catch( (error) => {

Previously Requested Object

© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited TopPrevNext