如何构建自定义命令按钮以在 Microsoft Office 中执行 JavaScript 功能?
How to build a custom command button to execute JavaScript function in Microsoft Office?
我要做的是添加一个自定义命令按钮以在 Microsoft Office(Word 或 Excel)中执行 JavaScript 功能。
具体来说,我需要构建一个命令来复制打开的文档文件 (Word/Excel) 的 link。
我能够像下图那样使用 Office Add-in 使用任务窗格构建加载项。
但是我可以在没有任务窗格的情况下构建命令按钮吗?
理想情况下,命令按钮应该复制打开的文档文件的 link 并显示成功对话框。
命令按钮也应该用于 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>
...
这个有货吗?
目前,Excel 不支持将工作表网格上的按钮或形状与 Javascript 函数链接起来。您将需要为这些使用任务窗格。
问题是因为我使用的是旧版本的 Office。
我尝试使用 Office 2016 构建加载项,但都失败了。
但是当我尝试使用最新版本的 Office 时,一切都对我有用。
我要做的是添加一个自定义命令按钮以在 Microsoft Office(Word 或 Excel)中执行 JavaScript 功能。
具体来说,我需要构建一个命令来复制打开的文档文件 (Word/Excel) 的 link。
我能够像下图那样使用 Office Add-in 使用任务窗格构建加载项。
但是我可以在没有任务窗格的情况下构建命令按钮吗?
理想情况下,命令按钮应该复制打开的文档文件的 link 并显示成功对话框。
命令按钮也应该用于 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>
...
这个有货吗?
目前,Excel 不支持将工作表网格上的按钮或形状与 Javascript 函数链接起来。您将需要为这些使用任务窗格。
问题是因为我使用的是旧版本的 Office。 我尝试使用 Office 2016 构建加载项,但都失败了。 但是当我尝试使用最新版本的 Office 时,一切都对我有用。