Excel.Run

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.


Example

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

Excel.run ( function (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");
    range2.load('values');
    return context.sync(range2)
    .then(function (range3)
    {
        var cellvalue1 = range3.values[0][0];
        console.log(cellvalue1);
        var range4 = sheet1.getRange("A3:B4");
        range4.load('values');
        return context.sync(range4);
    })
    .then(function (range5)
    {
        var cellvalue2 = range5.values[0][0];
        console.log(cellvalue2);
        var range6 = sheet1.getRange("A5:B6");
        range6.load('values');
        return context.sync(range6);
    })
    .then(function (range7)
    {
        var cellvalue3 = range7.values[0][0];
        console.log(cellvalue3);
        return context.sync();
    })
}).then(function () { console.log("Finished");
}).catch(function (error) { console.log(error);
});


Previously Requested Object






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