用角写的单词加载项-查找和选择文本

时间:2018-09-24 12:56:49

标签: angular typescript office-js

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

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

谢谢!

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
        });
    }
}

1 个答案:

答案 0 :(得分:1)

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

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