Does the Excel desktop client have a DOM Document, and how do I get to it?

28 Views Asked by At

I'm writing an OfficeJs addin that has both a task pane for complex tasks and adds menu items to the worksheet cell right-click menu for common/simple tasks. One of those tasks is copying something to the clipboard.

I can use either the separate or shared JavaScript envs. I find that when I run an action from the taskpane:

navigator.clipboard.writeText(text);

works fine, but when I run it from a command menu, I get an error that the copy failed because the Document doesn't have the focus. That makes some sense because:

  • When running in Shared mode, the Document is the Task Pane, and the task pane isn't showing
  • When running in Separate mode, the Actions don't have a UI, so can't have the focus, and trying the old (deprecated) method if document.execCommand("copy") always returns false (not enabled/supported).

So does the Excel workbook/worksheet/context/document or anywhere in the Excel/Office object model have a DOM Document or window that has the focus, which I can use to call clipboard.writeText()?

If no, can I use Office.UI.displayDialogAsync to open a 1px x 1px dialog, use it to copy to the clipboard, then immediately close it?

Also when running in the Office.web, I see that the iframe now includes the permissions for clipboard use, but only from the appstore url, not from localhost - so I can't test it.

0

There are 0 best solutions below