In my script, I need to refer to a specific row by using the number in a variable. For example, if the variable "rownumber"
is 21, I want to have this code line:
var final_row = target_sheet.getRange('21:21');
You can use the getRange(row, column, numRows, numColumns)
version of getRange
:
var rownumber = 21;
var final_row = target_sheet.getRange(rownumber,1,1,target_sheet.getMaxColumns());
getMaxColumns()
will give you the full row until the last column of your sheet, starting from the first column.
Alternatively, you can use getLastColumn()
to get from the first column until the last column with content:
var rownumber = 21;
var final_row = target_sheet.getRange(rownumber,1,1,target_sheet.getLastColumn());
There are multiple ways to do this:
var final_row = target_sheet.getRange(`${rownumber}:${rownumber}`);
+
var final_row = target_sheet.getRange(rownumber + ':' + rownumber);
Array.prototype.join()
var final_row = target_sheet.getRange([rownumber, rownumber].join(':');
Resources
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.