是否可以使用word网页插件获取光标位置?

问题描述 投票:2回答:1

我有一个需求,我需要根据光标位置在word文档中插入数据。有什么方法可以得到光标的位置吗?

ms-word office-js office-addins word-addins
1个回答
0
投票

正如你可以读到的 API文档你必须得到选区(curser是一个空选区),然后可以在选区之前或之后插入文本。

let cursorOrSelection = context.document.getSelection();
context.load(cursorOrSelection);
await context.sync();
cursorOrSelection.insertText("Important text to insert", Word.InsertLocation.end);
await context.sync();

可能的插入位置列在 API

如果你需要确定目前没有选择,只有一个诅咒者,你需要查看 isEmpty 范围内 cursorOrSelection. 更多关于您可以使用该系列的信息,请参见 API

© www.soinside.com 2019 - 2024. All rights reserved.