Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script Google Sheets脚本,用于打开多页文档中最后修改的页_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script Google Sheets脚本,用于打开多页文档中最后修改的页

Google apps script Google Sheets脚本,用于打开多页文档中最后修改的页,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我有一份多页文件。一年中每周的一张床单。打开文档时,这些工作表的名称为W1->W53,我更喜欢本周打开的“附近”工作表。如果GoogleSheets能够检测到最后修改的单元格,并打开引用的工作表,那么我正在寻找的工作表大部分时间都会被打开 谁能帮帮我吗 我试过这个脚本,但不起作用 函数onOpen(){ var lastModifiedSheet=UserProperties.getProperty(“mySheetName”); var lastModifiedCell=UserPropert

我有一份多页文件。一年中每周的一张床单。打开文档时,这些工作表的名称为W1->W53,我更喜欢本周打开的“附近”工作表。如果GoogleSheets能够检测到最后修改的单元格,并打开引用的工作表,那么我正在寻找的工作表大部分时间都会被打开

谁能帮帮我吗

我试过这个脚本,但不起作用

函数onOpen(){ var lastModifiedSheet=UserProperties.getProperty(“mySheetName”); var lastModifiedCell=UserProperties.getProperty(“myCell”); SpreadsheetApp.getActiveSpreadsheet() .getSheetByName(lastModifiedSheet).getRange(lastModifiedCell.activate(); } 回答: 您可以使用
onEdit()
触发器设置属性,然后使用
onOpen()
触发器检索属性

更多信息 修改您已经提供的代码:

函数onEdit(e){
var lms=PropertiesService.getScriptProperties()
.getProperty(“最后修改的表”);
var lmc=PropertiesService.getScriptProperties()
.getProperty(“lastModifiedCell”);
if(lms==e.range.getSheet().getName()&&lmc==e.range.getA1Notation()){
返回;
}
否则{
PropertiesService.getScriptProperties()
.setProperty(“lastModifiedSheet”,例如range.getSheet().getName());
PropertiesService.getScriptProperties()
.setProperty(“lastModifiedCell”,e.range.getA1Notation());
}  
}
然后
onOpen()

函数onOpen(){ var lastModifiedSheet=PropertiesService.getScriptProperties() .getProperty(“最后修改的表”); var lastModifiedCell=PropertiesService.getScriptProperties() .getProperty(“lastModifiedCell”); SpreadsheetApp.getActiveSpreadsheet().getSheetByName(lastModifiedSheet) .getRange(lastModifiedCell).activate(); } 此脚本的详细信息:

  • 每次编辑图纸时,图纸名称和单元格都会保存到特性中
  • 每次打开图纸时,它都会从属性中读取图纸名称和单元格,并激活该单元格
我希望这对你有帮助

参考资料:
答案: 您可以使用
onEdit()
触发器设置属性,然后使用
onOpen()
触发器检索属性

更多信息 修改您已经提供的代码:

函数onEdit(e){
var lms=PropertiesService.getScriptProperties()
.getProperty(“最后修改的表”);
var lmc=PropertiesService.getScriptProperties()
.getProperty(“lastModifiedCell”);
if(lms==e.range.getSheet().getName()&&lmc==e.range.getA1Notation()){
返回;
}
否则{
PropertiesService.getScriptProperties()
.setProperty(“lastModifiedSheet”,例如range.getSheet().getName());
PropertiesService.getScriptProperties()
.setProperty(“lastModifiedCell”,e.range.getA1Notation());
}  
}
然后
onOpen()

函数onOpen(){ var lastModifiedSheet=PropertiesService.getScriptProperties() .getProperty(“最后修改的表”); var lastModifiedCell=PropertiesService.getScriptProperties() .getProperty(“lastModifiedCell”); SpreadsheetApp.getActiveSpreadsheet().getSheetByName(lastModifiedSheet) .getRange(lastModifiedCell).activate(); } 此脚本的详细信息:

  • 每次编辑图纸时,图纸名称和单元格都会保存到特性中
  • 每次打开图纸时,它都会从属性中读取图纸名称和单元格,并激活该单元格
我希望这对你有帮助

参考资料:

您的电子表格是如何设置的?第一张是第1周,第二张是第2周,等等?不,不是。它以一个概述选项卡开始,中间有一个赛季中期选项卡。这些表的名称是否相关?(例如,第一周、第二周、第三周)我认为使用onOpen()触发器打开相应的选项卡可能会更容易。如果不设置属性,更新的
onOpen()
将无法工作
onEdit()
谢谢。有关于如何设置此onEdit()属性的提示吗?我必须说我在这个领域是一个真正的新手你的电子表格是如何设置的?第一张是第1周,第二张是第2周,等等?不,不是。它以一个概述选项卡开始,中间有一个赛季中期选项卡。这些表的名称是否相关?(例如,第一周、第二周、第三周)我认为使用onOpen()触发器打开相应的选项卡可能会更容易。如果不设置属性,更新的
onOpen()
将无法工作
onEdit()
谢谢。有关于如何设置此onEdit()属性的提示吗?我必须说我在这个领域是一个真正的新手