OfficeJ/WordJ通过索引选择文本范围并绑定单击事件 [英] OfficeJs/WordJs select text range by index and bind click event

查看:74
本文介绍了OfficeJ/WordJ通过索引选择文本范围并绑定单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 首先,如何使用OfficeJS/WordJS在索引和长度中选择段落中的文本.例如,我的段落有100个字符,我需要从索引2到索引16中选择所有字符.
  2. 第二,当我找到此范围时-如何为该范围添加事件处理程序?我的意思是,当用户单击我的段落中的2-16个字符时,我会在加载项中显示一些有用的信息.
  1. First, Using OfficeJS/WordJS how can I select text in a paragraph by index and length. For example, my paragraph has 100 characters and I need to select all from index 2 till index 16.
  2. Second, When I found this range - how I can add an event handler for this range? I mean, when user click at 2-16 chars in my paragraph - I will show some useful information in my Add-in.

我正在使用Word 2016加载项. 谢谢!

I'm using Word 2016 Add-in. Thanks!

推荐答案

我建议您探索1.3版更新中添加的Range功能,该功能目前正在预览中.请按照此处的说明进行操作.请添加的Range对象功能(所有要求集在最后一列中为1.3)

I recommend you to explore the Range functionalities we added as part of the 1.3 update who is in preview right now. Please follow the instructions here on how to try the preview. please explore the added Range object functionalities (all whose Req set are 1.3 in the last column)

请浏览"

Please explore the "split" functionality who enables you to split a paragraph into chunks of ranges when a set of delimiters is provided. For instance you can specify a space (" ") delimiter and get all the words in that paragraph. Check this example (exercise 7 on the lab) that splits a paragraph into words.

结合拆分功能,可以使用 getRange

In conjunction with the split functionality, you can use getRange and expandTo methods to expand a range. (so you get from index 'x' to 'y'

关于第二个问题.有了范围后,可以用标题内容控件包装它(range.insertContentControl,然后为其指定标题),以便可以使用

on your second question. Once you have the range, you can wrap it with a titled content control (range.insertContentControl and then specify a title for it), so that you can use the Office.context.bindings.addToNamedItemAsync API to create a Textbinding and subscribe to the BindingSelected event, as shown on this example.

希望这会指导您正确的方向.

Hope this guides you in the right direction.

这篇关于OfficeJ/WordJ通过索引选择文本范围并绑定单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆