小编Val*_*Val的帖子

Office-js Excel 插件:何时返回 context.sync()

我很难理解何时使用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)

javascript excel office-addins office365-apps office-js

3
推荐指数
1
解决办法
2632
查看次数