我很难理解何时使用context.sync().
这是一个基本的例子,但它又让我缺乏理解:
Excel.run(function (context){
const wb = context.workbook;
const ws = wb.worksheets.getActiveWorksheet();
// should never happened, but is it correct to check like this ?
if (wb === null) {
// IS IT CORRECT TO DO THIS ?
// I just want to exit the function
// return; would be enough ? What's going on in the callstack?
return context.sync();
}
ws.load("name");
return context.sync().then(function() {
var name = wb.name;
// do stuff
var range = ws.getRangeByIndexes(1,1,10,10);
return context.sync().then(function() …Run Code Online (Sandbox Code Playgroud)