[英]google apps script return row value in a cell
I have made this Apps script code:我已经制作了这个 Apps 脚本代码:
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0]
var f = sheet.getActiveCell().getRow();
var values = [ [ f ] ];
var range = sheet.getRange(4,4);
range.setValues(values);
}
And the purpose is to return in the cell D4
the number of the row of the activecell
.目的是在单元格D4
返回activecell
的行activecell
。 But everytime I try, it returns me the value "1" instead.但是每次我尝试时,它都会返回值“1”。
It seems to be a known bug of the Spreadsheet API: https://code.google.com/p/google-apps-script-issues/issues/detail?id=3496这似乎是电子表格 API 的一个已知错误: https : //code.google.com/p/google-apps-script-issues/issues/detail?id=3496
I have found a workaround, but you need to hard code the sheet name:我找到了一种解决方法,但您需要对工作表名称进行硬编码:
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
//var sheet = ss.getSheets()[0]
var sheet = ss.getSheetByName("Sheet1");
var active = sheet.getActiveCell();
var f = active.getRowIndex();
var values = [ [ f ] ];
var range = sheet.getRange(4,4);
range.setValues(values);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.