简体   繁体   English

如何通过Google Apps脚本从Google文档中的位置确定命名范围

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

I am looking at a way to determine the named range in Google docs through Google Apps Script for the current cursor position. 我正在寻找一种通过Google Apps脚本确定当前光标位置的Google文档中命名范围的方法。 Is there anyway to do that? 反正有这样做吗?

Context: I am marking a range in the google document for review using named range. 上下文:我正在使用命名范围在Google文档中标记一个范围以供审核。 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? 您能否让我知道Google Apps脚本中是否有办法? thanks Jasper 谢谢贾斯珀

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

cursor is a "Position". cursor是一个“位置”。

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. 让我知道是否有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM