我是一个相对新手。我在Google电子表格中列出了一长串费用,我希望它能够根据我打开工作表的当前月份跳转到此列表中的相应位置。每个月有200行,所以我希望它能做到这样的事情:
= MONTH(TODAY())*200
但这在脚本中不起作用。我试过从执行此功能的单元格中拉出它,但我不知道该怎么做。在下面的例子中,我可以跳到九月,因为我定义了
var monthrow = 1800
但是根据今天的日期,如何在剩下的几个月里做到这一点?谢谢你的帮助!
function onOpen() {
goToSheet2b()
}
function goToSheet2b() {
var monthrow = 1800
goToSheet("Expenses", monthrow, 2);
}
function goToSheet(sheetName, row, col) {
var sheet = SpreadsheetApp.getActive().getSheetByName(sheetName);
SpreadsheetApp.setActiveSheet(sheet);
var range = sheet.getRange(row, col)
SpreadsheetApp.setActiveRange(range);
答案 0 :(得分:0)
如果我理解正确,如果每月从1月开始确实有200行,则以下内容应该对您有用。我也对代码进行了评论。如果您有任何问题,请告诉我。
function onOpen() {
var d = new Date(new Date().getTime());
var month = d.getMonth(); //.getMonth() returns values form 0 (Jan) to 11 (Dec)
var monthrow = month*200 + 1; //we add the 1 because if it is Jan than 0*200 = 0 + 1 = 1 or row number 1 and for the rest it will be the start of that month
goToSheet("Expenses", monthrow, 2);
}
答案 1 :(得分:0)
谢谢!
我不得不调整操作顺序。这是对我有用的全部内容:
function onOpen() {
goToSheet2b()
}
function goToSheet2b() {
var d = new Date(new Date().getTime());
var month = d.getMonth(); //.getMonth() returns values form 0 (Jan) to 11 (Dec)
var monthrow = (month+1)*200;//we add the 1 because if it is Jan than 0*200 = 0 + 1 = 1 or row number 1 and for the rest it will be the start of that month
goToSheet("Expenses", monthrow, 2);
}
function goToSheet(sheetName, row, col) {
var sheet = SpreadsheetApp.getActive().getSheetByName(sheetName);
SpreadsheetApp.setActiveSheet(sheet);
var range = sheet.getRange(row, col)
SpreadsheetApp.setActiveRange(range);}