首页 > 解决方案 > 以角度编写的单词插件 ​​- 查找并选择文本

问题描述

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

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

谢谢!

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

标签: angulartypescriptoffice-js

解决方案


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

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


推荐阅读