How to determine the named range from position in Google Docs through Google Apps Script

流过昼夜 提交于 2019-12-13 05:49:32

问题


I am looking at a way to determine the named range in Google docs through Google Apps Script for the current cursor position. Is there anyway to do that?

Context: I am marking a range in the google document for review using named range. I would like to get the named range if the cursor is placed in that location of the document so that I can show that there is a review item on that area.

Could you please let me know if there is a way to do that in Google Apps Script? thanks Jasper


回答1:


var cursor = DocumentApp.getActiveDocument().getCursor();

cursor is a "Position".

A "Position" can tell you several things, for example the element which holds the position. Be careful: The thinking of a position is quite opposite: A position cannot contain other elements. A position is contained within an element.

So i think you could search your named ranges for this element:

cursor.getElement()

You have to iterate through your ranges, i think and if there is a match ... bingo.

Let me know if this helps.



来源:https://stackoverflow.com/questions/37280893/how-to-determine-the-named-range-from-position-in-google-docs-through-google-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!