【问题标题】:word add-in written in angular - find and select text以角度编写的单词插件 ​​- 查找并选择文本
【发布时间】:2018-09-24 12:56:49
【问题描述】:

我负责一个单词插件,需要添加新功能,但我失败了,希望有人能帮助我:)

我有一个按钮,如果单击此按钮,则应在单词文本中选择给定字符串的第一次出现。

谢谢!

package.json "@types/office-js": "0.0.75",

编辑:

HTML 代码

<a href="#" class="button-select-text (click)="selectText(givenString)">

角度代码

public selectText(givenString: string) {
    console.log('String to select: ' + givenString);
    if (this._common.officeVersion[0] !== '16') {
        this._common.getWordFile('', Office.FileType.Text)
            .then(response => {
                console.log('Text from Word: ' + response.fileContent);
                // todo now select/mark the givenString in word itself
            });

    } else {
        Word.run(context => {
            const wordText = context.load(context.document.body, 'text');
            console.log('Text from Word: ' + wordText);
            // todo now select/mark the givenString in word itself
        });
    }
}

【问题讨论】:

  • 很难理解你的问题,你能给出任何代码吗?或者生成一个 stackblitz 链接?
  • 我添加了coden-ps,但我的问题是我不知道如何从插件中选择/标记word中的文本
  • 我无法为您提供这些信息,如果您可以在 stackblitz 中上传一个版本来测试和“玩”它,也许我应该帮助您,因为我从未使用过 office-js。顺便说一句,我希望你能找到帮助!问候
  • 我建议您从 Script Lab - 一个在 Word 应用程序界面中运行的免费插件开始。它在 TypeScript 中提供了大量示例,其中一个演示了如何搜索一个术语。
  • @Cindy Meister 谢谢,我会研究一下 Script Lab 的样本!

标签: angular typescript office-js


【解决方案1】:

Word.run中,可以使用Word.Range.select()方法在Word中选择字符串。

我找不到使用共享 API(您在 2016 年之前的代码分支中使用的)以编程方式选择数据的方法。

【讨论】:

  • 所以只能在 Word 2016+ 中选择字符串?
  • @ColdFridge 据我所知,只有在 Word 2016+ 中才有可能
猜你喜欢
  • 2013-11-12
  • 1970-01-01
  • 2023-04-04
  • 2012-10-31
  • 1970-01-01
  • 2021-12-25
  • 2017-11-08
  • 2015-12-14
  • 1970-01-01
相关资源
最近更新 更多