【问题标题】:Taskpane is not loading with page upon clicking on ribbon icon excel add in单击功能区图标 excel 添加时,任务窗格未加载页面
【发布时间】:2021-10-19 09:26:05
【问题描述】:

我正在使用带有 react 的 officeJS 来创建 excel 插件。我添加了带有几个功能区按钮的功能区选项卡,单击功能区按钮我想在任务窗格上显示特定页面。我参考Excel-shared-runtime-scenario

创建了功能区

PSB 是清单中的我的控件:

<CustomTab id="ShareTime">
<Group id="ServiceGroup">
    <Label resid="ServiceGroup.Label"/>
    <Icon>
        <bt:Image size="16" resid="Icon.16x16"/>
        <bt:Image size="32" resid="Icon.32x32"/>
        <bt:Image size="80" resid="Icon.80x80"/>
    </Icon>
    <Control xsi:type="Button" id="BtnLoginService">
        <Label resid="BtnLoginService.Label" />
        <Supertip>
            <!-- ToolTip title. resid must point to a ShortString resource. -->
            <Title resid="BtnLoginService.Label" />
            <!-- ToolTip description. resid must point to a LongString resource. -->
            <Description resid="BtnLoginService.Tooltip" />
        </Supertip>
        <Icon>
            <bt:Image size="16" resid="Icon.16x16"/>
            <bt:Image size="32" resid="Icon.32x32"/>
            <bt:Image size="80" resid="Icon.80x80"/>
        </Icon>
        <!-- This is what happens when the command is triggered (E.g. click on the Ribbon). Supported actions are ExecuteFunction or ShowTaskpane. -->
        <Action xsi:type="ExecuteFunction">
            <FunctionName>btnloginservice</FunctionName>
        </Action>
    </Control>
    <Control xsi:type="Button" id="BtnLogoutService">
        <Label resid="BtnLogoutService.Label" />
        <Supertip>
            <!-- ToolTip title. resid must point to a ShortString resource. -->
            <Title resid="BtnLogoutService.Label" />
            <!-- ToolTip description. resid must point to a LongString resource. -->
            <Description resid="BtnLogoutService.Tooltip" />
        </Supertip>
        <Icon>
            <bt:Image size="16" resid="SignOutButton.Icon"/>
            <bt:Image size="32" resid="SignOutButton.Icon"/>
            <bt:Image size="80" resid="SignOutButton.Icon"/>
        </Icon>
        <!-- This is what happens when the command is triggered (E.g. click on the Ribbon). Supported actions are ExecuteFunction or ShowTaskpane. -->
        <Action xsi:type="ExecuteFunction">
            <FunctionName>btnlogoutservice</FunctionName>
        </Action>
        <Enabled>false</Enabled>
    </Control>
    <Control xsi:type="Button" id="BtnHomeService">
        <Label resid="BtnHomeService.Label" />
        <Supertip>
            <!-- ToolTip title. resid must point to a ShortString resource. -->
            <Title resid="BtnHomeService.Label" />
            <!-- ToolTip description. resid must point to a LongString resource. -->
            <Description resid="BtnHomeService.Tooltip" />
        </Supertip>
        <Icon>
            <bt:Image size="16" resid="Icon.16x16"/>
            <bt:Image size="32" resid="Icon.32x32"/>
            <bt:Image size="80" resid="Icon.80x80"/>
        </Icon>
        <!-- This is what happens when the command is triggered (E.g. click on the Ribbon). Supported actions are ExecuteFunction or ShowTaskpane. -->
        <Action xsi:type="ExecuteFunction">
            <FunctionName>btnhomeservice</FunctionName>
        </Action>
        <Enabled>false</Enabled>
    </Control>                          
</Group>

以下是我的 command.js 文件,其中包含全局可用的功能:

    import {
    SetRuntimeVisibleHelper,
    updateRibbon,
    signInFromRibbonO365,
    signOutO365FromRibbon,
} from 'utils/excelUtils/office-apis-helpers';
import { createHashHistory } from 'history';

export function getGlobal() {
    console.log('init globals for command buttons');
    if (typeof window !== 'undefined') {
        return window;
    }
    if (typeof global !== 'undefined') {
        return global;
    }
    return undefined;
}

const g = getGlobal();

export function btnloginservice(event) {
    const appHistory = createHashHistory();
    SetRuntimeVisibleHelper(true);
    // appHistory.replace('/login');
    // appHistory.push('/login');
    const port = window.location.port ? `:${window.location.port}` : '';
    const root = `${window.location.protocol}//${window.location.hostname}${port}`;
    console.log('path=', `${root}/#/login`);
    window.location.href = `${root}/#/login`;
    // signInFromRibbonO365();
    event.completed();
}

export function btnlogoutservice(event) {
    const appHistory = createHashHistory();
    console.log('Open logout dialog');
    // signOutO365FromRibbon();
    appHistory.push('/logout');
    event.completed();
}

export function btnhomeservice(event) {
    const appHistory = createHashHistory();
    SetRuntimeVisibleHelper(true);
    // history.push('/');
    appHistory.replace('/');
    event.completed();
}

export function btnfeedbackservice(event) {
    const appHistory = createHashHistory();
    SetRuntimeVisibleHelper(true);
    window.open(
        'https://facebook.com',
        '_blank',
    );
    appHistory.push('/feedback');
    event.completed();
}

// the add-in command functions need to be available in global scope
g.btnloginservice = btnloginservice;
g.btnlogoutservice = btnlogoutservice;
g.btnhomeservice = btnhomeservice;
g.btnfeedbackservice = btnfeedbackservice;

当我在本地使用 localhost 在在线和桌面 excel 上运行代码时,这可以正常工作,启用/禁用功能区操作也可以正常工作。

但是当我在天蓝色云上部署应用程序时,相同的代码不适用于桌面 excel(办公室在线 excel 工作)。单击功能区登录菜单后,它不会将页面重定向到任务窗格。它没有重定向到给定的路径。

请帮助实现从功能区单击时调用的命令函数的重定向。或提出正确的实施方法

想要在功能区操作的任务窗格上重定向页面。

第一次点击功能区菜单来加载和执行该操作的命令功能也需要一些时间,知道如何提高功能区菜单点击的性能

【问题讨论】:

  • 在任务窗格中放置一个按钮是否有效?那么,如果您从任务窗格窗口运行命令,它在 Azure 中是否按预期工作?您的清单文件中是否将域列入白名单?
  • 感谢 Eugene 的评论,是的,如果我们将按钮放在任务窗格中,它甚至可以直接在本地使用 localhost 单击功能区。是的,在 manifestapp.appserviceenvironment.net/</AppDomain> 中使用 AppDomains 将域列入白名单。如果我从 azure 部署的应用程序运行流程,即使尝试使用 window.location.href 仍然无法重定向到页面,history.push 也不起作用。但同样适用于 chrome 上的 office365 online excel。
  • 我认为目前在 OfficeJS 中这是一个可能且受支持的方案 - 从任务窗格上的无 UI 功能导航到网页。您可以做的最好的事情是分配一个按钮来打开一个任务窗格,您可以在其中重新导航到所需的页面。
  • 但如果我尝试在本地运行流,则同样适用于本地主机。使用 history.push() 或 window.location.href 在任务窗格中重定向页面是否正确?任何其他建议

标签: reactjs excel office-js excel-addins


【解决方案1】:

如果您想通过按钮单击或某些操作向用户显示任何网页,请尝试使用window.open('https://anysite.dom')。如果您的清单中将域列入白名单,这应该可以工作。

【讨论】:

  • window.open() 将打开新标签页。我想在任务窗格中打开相同的应用程序页面。就像只是想路由页面。
猜你喜欢
  • 2011-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多