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

非Windows环境下Office Content Add-in开发相关问题咨询

解答Office Content Add-in开发的三个问题

1. 为Content Add-in指定默认宽度

你之前加<RequestedWidth>出现验证错误,大概率是节点位置放错了。这个元素必须嵌套在DesktopSettings节点下,正确的manifest结构示例如下:

<OfficeApp ...>
  <!-- 其他配置节点 -->
  <Hosts>
    <Host Name="Document">
      <DesktopSettings>
        <RequestedWidth>350</RequestedWidth> <!-- 数值范围150-1000,单位为像素 -->
        <RequestedHeight>500</RequestedHeight>
        <SourceLocation DefaultValue="https://你的插件加载地址"/>
      </DesktopSettings>
    </Host>
  </Hosts>
  <!-- 其他配置节点 -->
</OfficeApp>

确保节点嵌套符合Office Add-in的manifest schema规范,这样就能通过验证,同时生效默认宽度设置。

2. 实现点击功能区命令才插入Add-in

要取消自动加载、改成触发式插入,需要两步操作:

  • 移除manifest中DefaultSettings下的自动加载配置(如果存在)
  • 添加功能区扩展点,定义触发按钮,指定动作类型为InsertContentPane

核心配置代码示例:

<OfficeApp ...>
  <!-- 其他配置节点 -->
  <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
    <Hosts>
      <Host xsi:type="Document">
        <DesktopFormFactor>
          <!-- 定义功能区自定义按钮 -->
          <ExtensionPoint xsi:type="PrimaryCommandSurface">
            <CustomTab Id="MyAddin.Tab">
              <Group Id="MyAddin.Group">
                <Label resid="MyAddin.Group.Label"/>
                <Icon>
                  <bt:Image size="16" resid="MyAddin.Icon.16x16"/>
                  <bt:Image size="32" resid="MyAddin.Icon.32x32"/>
                  <bt:Image size="80" resid="MyAddin.Icon.80x80"/>
                </Icon>
                <Control xsi:type="Button" id="MyAddin.InsertButton">
                  <Label resid="MyAddin.InsertButton.Label"/>
                  <Supertip>
                    <Title resid="MyAddin.InsertButton.Title"/>
                    <Description resid="MyAddin.InsertButton.Description"/>
                  </Supertip>
                  <Icon>
                    <bt:Image size="16" resid="MyAddin.Icon.16x16"/>
                    <bt:Image size="32" resid="MyAddin.Icon.32x32"/>
                    <bt:Image size="80" resid="MyAddin.Icon.80x80"/>
                  </Icon>
                  <!-- 点击按钮触发插入动作 -->
                  <Action xsi:type="InsertContentPane">
                    <ContentPaneId>MyAddin.ContentPane</ContentPaneId>
                  </Action>
                </Control>
              </Group>
              <Label resid="MyAddin.Tab.Label"/>
            </CustomTab>
          </ExtensionPoint>

          <!-- 定义要插入的ContentPane内容 -->
          <ContentPane Id="MyAddin.ContentPane">
            <SourceLocation DefaultValue="https://你的插件加载地址"/>
            <RequestedWidth>350</RequestedWidth>
            <RequestedHeight>500</RequestedHeight>
          </ContentPane>
        </DesktopFormFactor>
      </Host>
    </Hosts>
    <!-- 资源定义等其他节点 -->
  </VersionOverrides>
  <!-- 其他配置节点 -->
</OfficeApp>

配置完成后,只有用户点击功能区的自定义按钮,Content Add-in才会插入到文档中,不会自动加载。

3. Content Add-in对应ShowTaskpane的替代元素

Task Pane用<ShowTaskpane>唤起侧边面板,而Content Add-in是插入到文档内容区域的面板,对应的动作元素是<InsertContentPane>——就是上面第二个问题示例里用到的动作,它会将你定义好的ContentPane插入到当前光标位置或文档指定区域。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 11:49:54