gpt4 book ai didi

javascript - 使用office.js插入word后失去选择

转载 作者:行者123 更新时间:2023-11-28 08:05:01 26 4
gpt4 key购买 nike

我正在构建一个将在 Microsoft Word 中运行的 Office 应用程序。我正在使用office.js 创建它。

到目前为止,我已经能够使用 API 将文本插入到文档中,但它插入的文本似乎已被选中,这使得应用程序的用户体验受到影响,因为用户必须额外单击一次才能失去焦点,才能插入另一文本,而无需插入其他文本。替换插入的那个。

代码如下:

function insertEquation()
{
Office.context.document.setSelectedDataAsync("`x = (-b +-sqrt(b^2-4ac))/(2a)`", { coercionType: 'text' });
}

我只是希望文本不显示为选中状态。

提前致谢。

最佳答案

要在文档中插入一些文本,我将插入一个段落,如下所示:

function insertText(text) {
Word.run(function (context) {
context.document.body.insertParagraph(text, Word.InsertLocation.start);
});
}

关于javascript - 使用office.js插入word后失去选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24895349/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com