似乎他们都做同样的事情,即在事件的“打开”工作表中返回选定的范围。我在这里缺少什么?是否存在需要使用 getSelection() 的情况?
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getActiveRange();
var selection = sheet.getSelection();
// These return the same values
Logger.log("Range Values: %s", range.getValues());
Logger.log("Selection Values: %s", selection.getActiveRange().getValues());
// These also return the same values
Logger.log("Sheet Current Cell: %s", sheet.getCurrentCell().getValue());
Logger.log("Selection Current Cell: %s", selection.getCurrentCell().getValue());
最佳答案
根据文档,有区别。getActiveRange()
返回类范围,但 getSelection()
返回类选择。不同之处在于选择可以是不相邻的范围。
因此,如果您需要获得选定的非相邻范围,则需要使用 getSelection()
范围只能是“工作表中的一组相邻单元格”
关于google-apps-script - getActiveRange() 和 getSelection() 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51162081/