Unable to edit worksheet in an Excel add-in (Offic

2019-02-20 01:00发布

In an Excel add-in, right after closing a dialog created using displayDialogAsync, you cannot edit the cells in the worksheet. If you click anywhere else outside the worksheet (ribbon, task pane, etc), minimize/maximize Excel, or double click a cell, then you can edit again. If you scroll while you cannot edit, everything in excel becomes "un-clickable".
Also, I have noticed that the title bar (where the name of document is shown) remains grayed out until you click outside the worksheet as if Excel didn't have focus.

I was able to reproduce this using the basic Excel Add-in template from Visual Studio:

In the manifest I added a button to the ribbon (to open the dialog):

 <Control xsi:type="Button" id="DDR.SettingsButton">
              <Label resid="DDR.SettingsButton.Label" />
              <Supertip>
                <!-- ToolTip title. resid must point to a ShortString resource. -->
                <Title resid="DDR.SettingsButton.Title" />
                <!-- ToolTip description. resid must point to a LongString resource. -->
                <Description resid="DDR.SettingsButton.Text" />
              </Supertip>
              <Icon>
                <bt:Image size="16" resid="Contoso.tpicon_16x16" />
                <bt:Image size="32" resid="Contoso.tpicon_32x32" />
                <bt:Image size="80" resid="Contoso.tpicon_80x80" />
              </Icon>

              <Action xsi:type="ExecuteFunction">
                <FunctionName>openDialog</FunctionName>
              </Action>

            </Control>

Then, a function to the Functions File:

function openDialog(event) {
    Office.context.ui.displayDialogAsync(window.location.origin + "/functions/Dialog.html", { height: 50, width: 50 }, function dialogCallback(asyncResult) {
        if (asyncResult.status !== "failed") {
           var dialog = asyncResult.value;
            dialog.addEventHandler(Office.EventType.DialogMessageReceived, function (args) {
                dialog.close();
                event.completed();
            });
            dialog.addEventHandler(Office.EventType.DialogEventReceived, function (arg) {
                switch (arg.error) {
                    case 12006:
                        event.completed();
                        break;
                    default:
                        break;
                }
            });
        }
    });
}

Then, I created a very simple dialog:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>
    <script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.2.1.min.js"></script>
    <script>
        Office.initialize = function () {
            $('#buttonClose').click(close);

        };

        function close() {
            Office.context.ui.messageParent("close");
        }

    </script>

</head>
<body>
    <Button id="buttonClose">Close</Button>
</body>
</html>

I experienced a very similar behavior that was being caused (now fixed) by an iframe that I was embedding in the task panel (original question here: Unable to edit cells after a setSelectedDataAsync in Excel).

Is there a workaround/fix for this?

Thanks!

0条回答
登录 后发表回答