, Excel.run OM . Excel.run , , .
, , . , Excel "" ".context". , , :
Excel.run(function (ctx) {
var worksheet = ctx.workbook.worksheets.getActiveWorksheet();
return ctx.sync(worksheet);
}).then(function(worksheet) {
worksheet.name = "Test"
return worksheet.context.sync();
}).catch(function(e) {
console.log(e)
});
, Excel.run, .
- Range, . , , ( ?) , , ). Excel.run Backing Range, Excel. Excel.run , . , :
Excel.run(function (ctx) {
var range = ctx.workbook.getSelectedRange();
return ctx.sync(range);
}).then(function(range) {
range.format.fill.color = "red";
return ctx.sync();
}).catch(function(e) {
console.log(e)
})
"InvalidObjectPath".
, ctx.trackedObjects. , , - , , , . , - Excel.
var range;
Excel.run(function (ctx) {
range = ctx.workbook.getSelectedRange();
ctx.trackedObjects.add(range);
return ctx.sync(range);
}).then(function(range) {
range.format.fill.color = "red";
return range.context.sync();
}).then(function() {
range.context.trackedObjects.remove(range);
range.context.sync();
}).catch(function(e) {
console.log(e);
})
: , , , Excel.run. , "". , Excel.run(, promises Excel.run, - ). , , , , (, ), onclick .. Excel.run, .
PS. , : , ctx.sync() Excel.run, - . promises .. ,
Excel.run(function (ctx) {
var range = ctx.workbook.worksheets.getActiveWorksheet().getRange("A1:C3");
range.load("values");
return ctx.sync()
.then(function () {
})
.then(ctx.sync)
.then(function () {
})
.then(ctx.sync)
.then(function() {
});
}).catch(function(error) {
console.log("Error: " + error);
});