Angular word加载项以角度书写-查找并选择文本

Angular word加载项以角度书写-查找并选择文本,angular,typescript,office-js,Angular,Typescript,Office Js,我负责一个word插件,需要添加新功能,但我很失败,希望任何人都能帮助我:) 我有一个按钮,如果单击此按钮,则应在word文本中选择给定字符串的第一次出现 谢谢大家! package.json “@types/officejs”:“0.0.75” 编辑: HTML代码 <a href="#" class="button-select-text (click)="selectText(givenString)"> 在Word.run中,可以使用该方法选择Word中的字符串 我找不到通

我负责一个word插件,需要添加新功能,但我很失败,希望任何人都能帮助我:)

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

谢谢大家!

package.json “@types/officejs”:“0.0.75”

编辑:

HTML代码

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

Word.run
中,可以使用该方法选择Word中的字符串


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

你的问题很难理解,你能展示一些代码吗?或者生成stackblitz链接?我添加了代码片段,但我的问题是,我不知道如何从add inI中选择/标记word中的文本无法帮助您获取这些信息,如果您可以在stackblitz中上载一个版本进行测试并“播放”,也许我应该帮助您,因为我从未使用过office js。顺便说一下,我希望你能找到帮助!RegardsI建议您从Script Lab开始—一个在Word应用程序界面中运行的免费外接程序。这在TypeScript中提供了许多示例,包括一个演示如何搜索术语的示例。@Cindy Meister谢谢,我将研究脚本实验室的示例!因此,只有在Word 2016+?@ColdFridge中才可能选择刺,据我所知,只有在Word 2016中才可能选择刺+
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
        });
    }
}