能否在Office Excel JavaScript Add-in自定义功能区添加Excel内置函数?
在Excel JavaScript Add-in自定义功能区中添加内置命令
可行性
完全可以实现。你无需编写额外的JavaScript逻辑,只要在加载项的清单文件中配置对应内置功能的命令ID,就能把Excel原生功能(比如删除重复项)添加到自定义功能区中,触发效果和点击原生功能区按钮完全一致。
清单文件XML示例
以下是将“删除重复项”功能添加到自定义选项卡的核心配置片段:
<VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0"> <Hosts> <Host xsi:type="Workbook"> <DesktopFormFactor> <!-- 自定义选项卡配置 --> <CustomTab id="MyCustomTab"> <Label resid="customTabLabel" /> <Group id="DataToolsGroup"> <Label resid="groupLabel" /> <!-- 绑定删除重复项内置命令的按钮 --> <Control xsi:type="Button" id="RemoveDuplicatesBtn"> <Label resid="removeDuplicatesLabel" /> <Supertip> <Title resid="removeDuplicatesTitle" /> <Description resid="removeDuplicatesDesc" /> </Supertip> <Icon> <!-- 可自定义图标,也可省略使用内置默认图标 --> <bt:Image size="16" resid="icon16" /> <bt:Image size="32" resid="icon32" /> <bt:Image size="80" resid="icon80" /> </Icon> <!-- 核心:调用内置命令的配置 --> <Action xsi:type="ExecuteFunction"> <FunctionName>Office.actions.invoke</FunctionName> <Parameters> <Parameter Name="actionId">Commands.RemoveDuplicates</Parameter> </Parameters> </Action> </Control> </Group> </CustomTab> </DesktopFormFactor> </Host> </Hosts> <!-- 资源配置(文本、图标等) --> <Resources> <bt:ShortStrings> <bt:String id="customTabLabel" DefaultValue="我的自定义工具" /> <bt:String id="groupLabel" DefaultValue="数据操作" /> <bt:String id="removeDuplicatesLabel" DefaultValue="删除重复项" /> <bt:String id="removeDuplicatesTitle" DefaultValue="删除重复项" /> </bt:ShortStrings> <bt:LongStrings> <bt:String id="removeDuplicatesDesc" DefaultValue="删除选中单元格区域内的重复行" /> </bt:LongStrings> <bt:Images> <bt:Image id="icon16" DefaultValue="https://your-add-in-domain/images/icon16.png" /> <bt:Image id="icon32" DefaultValue="https://your-add-in-domain/images/icon32.png" /> <bt:Image id="icon80" DefaultValue="https://your-add-in-domain/images/icon80.png" /> </bt:Images> </Resources> </VersionOverrides>
注意:Commands.RemoveDuplicates是对应“删除重复项”的内置命令ID,这是配置的核心部分。
查找Excel内置命令ID的方法
- 使用Office UI Fabric Command Explorer工具:这是Office开发工具集里的工具,可直接搜索功能名称(如“Remove Duplicates”)获取对应的命令ID,支持筛选Excel专属的命令。
- 查阅Office官方内置命令ID清单:里面按功能分类列出了所有Excel可用的内置命令ID,比如常用的还有:
Commands.SortAscending(升序排序)Commands.SortDescending(降序排序)Commands.ClearContents(清除内容)
内容的提问来源于stack exchange,提问作者user21249614
相关产品推荐
相关产品推荐

