问题
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