You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Office JS+Angular开发Excel插件调用ribbon.requestUpdate报Sharedruntime ID缺失

解决Office JS + Angular Excel插件中The Sharedruntime ID is missing错误

当调用Office.ribbon.requestUpdate()触发该错误,核心原因是共享运行时(Shared Runtime)的配置不完整或不符合要求,以下是针对性修复步骤:

1. 完善清单文件(manifest.xml)的共享运行时配置

必须确保清单中包含完整的<Runtime>节点,且指定唯一的id属性:

<Runtime resid="Taskpane.Url" lifetime="long" id="YourUniqueRuntimeId" />
  • id:必填项,自定义唯一标识(如ExcelAddinRuntime),后续所有依赖共享运行时的配置需匹配此ID
  • lifetime="long":必须设置为long,这是桌面端启用共享运行时的硬性要求

同时,在<VersionOverrides>的<DesktopFormFactor>下,确保功能区扩展点关联该运行时:

<ExtensionPoint xsi:type="CommandSurface">
  <CustomAction id="CustomRibbonButton" onAction="RibbonButtonClicked">
    <CommandExtension>
      <!-- 按钮基础配置 -->
    </CommandExtension>
  </CustomAction>
  <OfficeTab id="TabHome">
    <!-- 功能区组、控件配置 -->
  </OfficeTab>
</ExtensionPoint>

注意:所有需要动态更新的功能区命令,必须基于共享运行时环境,不能使用无UI的ExecuteFunction类型配置。

2. 等待Office上下文初始化完成后再执行ribbon更新

在Angular项目中,禁止过早调用Office.ribbon.requestUpdate(),必须在Office.onReady()回调完成后操作:

Office.onReady((info) => {
  if (info.host === Office.HostType.Excel) {
    // 在此执行ribbon启用/禁用操作
    Office.ribbon.requestUpdate({
      tabs: [
        {
          id: "TabHome",
          groups: [
            {
              id: "CustomGroup",
              controls: [
                {
                  id: "CustomButton",
                  enabled: false
                }
              ]
            }
          ]
        }
      ]
    }).catch(err => console.error(err));
  }
});

避免在组件ngOnInit等生命周期钩子中直接调用,除非已确认Office上下文完全初始化。

3. 验证清单版本覆盖配置

检查<VersionOverrides>中的<Commands>节点,确保命令的<Action>类型为ShowTaskpane(而非ExecuteFunction),且指向共享运行时加载的页面:

<Commands>
  <Command id="CustomButtonCommand">
    <Label resid="ButtonLabel" />
    <Supertip>
      <Title resid="ButtonTitle" />
      <Description resid="ButtonDesc" />
    </Supertip>
    <Icon>
      <!-- 图标配置 -->
    </Icon>
    <Action xsi:type="ShowTaskpane">
      <TaskpaneId>ButtonTaskpane</TaskpaneId>
      <SourceLocation resid="Taskpane.Url" />
    </Action>
  </Command>
</Commands>

4. 清理缓存并重新部署

  • 卸载当前Excel插件,重新加载修改后的清单文件
  • 清理Office插件缓存:打开Excel,依次点击文件->选项->信任中心->信任中心设置->受信任的加载项目录清除缓存;或手动删除%LOCALAPPDATA%\Microsoft\Office\16.0\Wef\下的缓存文件夹

内容的提问来源于stack exchange,提问作者Shukla Dev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 15:42:38