标签: office-js-helpers

Office JS application.createDocument() 打开带有关闭加载项的新窗口

我们从后端加载base64文档并在 Word 插件中打开它(使用 Office JS API)。我们正在application.createDocument(base64)这样做。这会导致 Word 应用程序为新文档打开一个全新的窗口,其中插件默认关闭。

我们的加载项受登录保护,因此重新打开加载项需要用户再次输入用户名/密码。

有没有办法 1) 不打开新的 MS-Word 窗口(替换 word 文档),或 2) 打开一个新的 MS-Word 窗口,其中插件已经打开,并将身份验证令牌从第一个 MS-Word 传递到第二?

openoffice-api office-js office-js-helpers

7
推荐指数
0
解决办法
322
查看次数

如何使用 Office JS 在 Word 文档正文中添加书签

Office JS 在preview 中提供了以下功能,但我找不到任何示例。

这是我尝试过的但似乎不起作用,不知道我在这里缺少什么,因为此代码插入了文本但未创建书签。

Word.run(function (context)
{
    let range = context.document.getSelection();
    return context.sync().then(function ()
    {
        range.insertText(`Test Bookmark`, Word.InsertLocation.replace);

        let uniqueStr = new Date().getTime();
        let bookmarkName = `Test_BookmarkCode_${uniqueStr}`;
        range.insertBookmark(bookmarkName);
    });
});
Run Code Online (Sandbox Code Playgroud)

交叉张贴在这里

ms-word office-addins office-js office-js-helpers

7
推荐指数
1
解决办法
352
查看次数

“Object.defineProperty(导出,“__esModule”,{值:true});“ 阻止 FunctionFile 中的函数执行

我按照本教程启动了一个带有 Typescript&React 的 Office Web 插件项目:https://github.com/OfficeDev/office-js-docs-pr/blob/master/docs/includes/file-get-started-excel-反应.md。任何任务窗格函数和页面都可以正常运行,但函数文件页面上的函数无法正确执行。

通过删除代码,我发现Object.defineProperty(exports, "__esModule", { value: true });编译后的 function-file.js 中的一行解决了问题。每当它出现时,文件中的任何函数都不会被执行。Fiddler 显示脚本已正确加载到 Excel 中,且没有任何警告。状态栏显示“[加载项名称]正在处理您的[功能名称]”。

这行代码是由 Typescript 编译器生成的,在本例中,用于加载节点模块“@microsoft/office-js-helpers”。我尝试修改 tsconfig.json 文件以避免生成该行,但随后“@microsoft/office-js-helpers”的导入失败。另外,Webpack 4 将在该文件中添加 webpackBootstrap 代码拦截功能。此时,我只能避免在 function-file.ts 中进行任何导入,并在通过 Webpack 构建项目后执行“tsc”。

我的问题是:设置该项目的正确方法是什么,以便 function-file.js 不包含任何阻止其函数执行的代码?如果没有明确的答案,至少,为什么这行代码会导致其他页面工作正常的问题?

以下是我的 tsconfig.json ,它可以避免该行但无法加载任何模块:

  "compilerOptions": {
    "target": "es5",
    "module": "es2015",
    "moduleResolution": "node",
    "lib": ["es2015", "dom"],
    "typeRoots": ["node_modules/@types"]
  },
Run Code Online (Sandbox Code Playgroud)

我手动将编译后的function-file.js编辑成两个版本:

Object.defineProperty(exports, "__esModule", { value: true });
(function () {
    Office.initialize = function () { }
    };
})();
function writeText(event) {
    Office.context.document.setSelectedDataAsync('test');
    event.completed();
}
Run Code Online (Sandbox Code Playgroud)

VS

(function …
Run Code Online (Sandbox Code Playgroud)

node.js typescript office-js office-js-helpers

5
推荐指数
1
解决办法
1万
查看次数

Office API getAccessTokenAsync result yields InvalidAuthenticationToken response from Graph

i have been trying to tackle this issues for a while now, i am workin on an Office-js addin for Outlook and is trying to access Microsoft Graph data through my addin.

But i have been unable to authenticate the token i recieve from getAccessTokenAsync. If i attempt to use the authenticator from Office-JS-Helpers i can get access, but i would prefer to use the built in function of the addin for it.

the code i am trying to use …

office-js microsoft-graph office-js-helpers

4
推荐指数
1
解决办法
388
查看次数

如何在 Angular 6 中使用 microsoft office-js 定义 Excel

我正在关注这个网站来集成office js

像这样声明:

import * as Excel from '@microsoft/office-js/excel' 它显示编译时错误:

找不到模块“@microsoft/office-js/excel”

像这样声明:

declare var Excel: any

它显示运行时错误:

错误 ReferenceError:Excel 未定义

请建议如何申报。我需要像这样使用它:

Excel.run(session, (context){
   ...
});
Run Code Online (Sandbox Code Playgroud)

office-addins typescript office-js angular office-js-helpers

1
推荐指数
1
解决办法
1570
查看次数