Google apps script 打开工作表时,是否希望根据日期自动跳转到特定单元格

Google apps script 打开工作表时,是否希望根据日期自动跳转到特定单元格,google-apps-script,google-sheets,Google Apps Script,Google Sheets,更新:根据之前的回答,我加入了要求谷歌重新启用这一能力的人群,他们显然已经答应了 现在我想知道如何实现它,因为我对谷歌表单中的脚本一无所知 下面是原始问题 我有一个电子表格,有许多不同的表格,需要每天输入数据。例如,有一张名为“美国销售”的表格,一年中的每一天都有一行。还有其他几张相同的表格,如英国销售、美国租赁等 我想聚焦自动跳转到适当的行,根据当前日期,每当这些表之一被打开 可能吗?如果是,如何实现?这通常可以通过一个简单的脚本来实现,该脚本带有一个onOpen函数,在打开电子表格时执行,并

更新:根据之前的回答,我加入了要求谷歌重新启用这一能力的人群,他们显然已经答应了

现在我想知道如何实现它,因为我对谷歌表单中的脚本一无所知

下面是原始问题 我有一个电子表格,有许多不同的表格,需要每天输入数据。例如,有一张名为“美国销售”的表格,一年中的每一天都有一行。还有其他几张相同的表格,如英国销售、美国租赁等

我想聚焦自动跳转到适当的行,根据当前日期,每当这些表之一被打开


可能吗?如果是,如何实现?

这通常可以通过一个简单的脚本来实现,该脚本带有一个onOpen函数,在打开电子表格时执行,并激活所需的单元格或工作表

但是,由于新版本的电子表格发生了变化,您很可能正在使用它,现在已经不可能了,请查看并随时启动它,希望谷歌团队能够改变主意,使之再次成为可能-

编辑:这个简单的代码在中工作,在新版本中不工作

function onOpen() {
  SpreadsheetApp.getActive().getSheets()[0].getRange('B6').activate();// an arbitrary cell
  // not worth trying more complex cell selection (on date or anything else) while this is blocked by design .
}
有关此更改的详细信息,请参阅下文。

编辑2: 2014年10月16日,该问题现已解决,上述代码也适用于新版电子表格

要自动激活对应于一年中某一天的行,可以使用如下代码:

function onOpen() {
  var day = new Date().getDOY();// this uses a custom date method that returns the day of the year and is defined below
  SpreadsheetApp.getActive().getSheets()[0].getRange(day,1).activate();// in cloumn 1 for example. Add an offset if necessary (if headers...)

}

Date.prototype.getDOY = function() {
var onejan = new Date(this.getFullYear(),0,1);
return Math.ceil((this - onejan) / 86400000);
}

这通常可以通过一个带有onOpen函数的简单脚本来实现,该函数在打开电子表格时执行,并激活所需的单元格或工作表

但是,由于新版本的电子表格发生了变化,您很可能正在使用它,现在已经不可能了,请查看并随时启动它,希望谷歌团队能够改变主意,使之再次成为可能-

编辑:这个简单的代码在中工作,在新版本中不工作

function onOpen() {
  SpreadsheetApp.getActive().getSheets()[0].getRange('B6').activate();// an arbitrary cell
  // not worth trying more complex cell selection (on date or anything else) while this is blocked by design .
}
有关此更改的详细信息,请参阅下文。

编辑2: 2014年10月16日,该问题现已解决,上述代码也适用于新版电子表格

要自动激活对应于一年中某一天的行,可以使用如下代码:

function onOpen() {
  var day = new Date().getDOY();// this uses a custom date method that returns the day of the year and is defined below
  SpreadsheetApp.getActive().getSheets()[0].getRange(day,1).activate();// in cloumn 1 for example. Add an offset if necessary (if headers...)

}

Date.prototype.getDOY = function() {
var onejan = new Date(this.getFullYear(),0,1);
return Math.ceil((this - onejan) / 86400000);
}

答案已根据您的规格更新。答案已根据您的规格更新。