【发布时间】:2020-12-01 22:03:12
【问题描述】:
我要做的是添加一个自定义命令按钮以在 Microsoft Office(Word 或 Excel)中执行 JavaScript 函数。
具体来说,我需要构建一个命令来复制打开的文档文件(Word/Excel)的链接。
我能够使用Office Add-in 使用任务窗格构建加载项,如下图所示。
但是我可以在没有任务窗格的情况下构建命令按钮吗?
理想情况下,命令按钮应该复制打开的文档文件的链接并显示成功对话框。
命令按钮也应该用于 Azure Active Directory 中的注册应用。
更新
关于文档,它说我可以使用 action xsi:type 作为 ExecuteFunction 而不是使用 ShowTaskpane,但它不能正常工作。
<?xml version="1.0" encoding="utf-8"?>
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0" xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="TaskPaneApp">
...
<DefaultSettings>
<SourceLocation DefaultValue="https://localhost:3000/commands.js" />
</DefaultSettings>
...
<Host xsi:type="Document">
<!-- Form factor. Currenly only DesktopFormFactor is supported. We will add TabletFormFactor and PhoneFormFactor in the future-->
<DesktopFormFactor>
...
<ExtensionPoint xsi:type="PrimaryCommandSurface">
<!--Use OfficeTab to extend an existing Tab. Use CustomTab to create a new tab -->
<!-- Documentation includes all the IDs currently tested to work -->
<CustomTab id="Contoso.Tab1">
...
<Action xsi:type="ExecuteFunction">
<!--Name of the function to call. This function needs to exist in the global DOM namespace of the function file-->
<FunctionName>writeText</FunctionName>
</Action>
</Control>
...
这个可以吗?
【问题讨论】: