加载项对话框中的 excel 上下文同步错误

Error on excel context sync in a addin dialog box

在我的 excel 任务窗格中,我使用以下代码显示主网页中的一个对话框。

Office.context.ui.displayDialogAsync(window.location.origin + "/Sample.html", { height: 50, width: 23 });

在 Sample.html 中,我有下面的代码,它会抛出一个错误 'An internal error has occurred.' 控件确实进入了 document.ready 块。请告诉我如何在插件对话框中使用 office.js 方法。

        Office.initialize = function (reason) {
        $(document).ready(function () {
            Excel.run(function (ctx) {
                var sheet = ctx.workbook.worksheets.getActiveWorksheet();  
                sheet.getRange("A1").values = [["test"]];

                return ctx.sync()
                    .then(function () {
                    })
                    .then(ctx.sync);
            })
            .catch(errorHandler);
        });
    }

已经存在类似问题here,但与对话框无关。

您只能在对话框中使用两个 Office JavaScript API:isSetSupportedmessageParent。请参阅此页面下方 1/3 处的重要说明:Dialog API in Office Add-ins