【发布时间】: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