Reputation: 2845
I want to get data from column A starting from cell A2 till cell A12. I try to use the following code but I keep getting error:
Cannot find method getDataRange(string). (line...
I don't want to use range = sheet.getDataRange();
because that will copy
entire sheet values! How I can fix above error ?
function getRangeData()
{
var sheet = SpreadsheetApp.getActiveSheet(),
range,
values_array;
range = sheet.getDataRange('A2:A12');
values_array = range.getValues();
Logger.log(values_array);
}
Upvotes: 0
Views: 4396
Reputation: 45720
The getDataRange()
function has no parameters. (documentation) You need to dig some more to find an alternate way to accomplish your wish.
The function that you are looking for is Sheet.getRange()
, which supports several ways to express the desired range, including one that takes a string expressing a range in A1Notation.
function getRangeData() {
var sheet = SpreadsheetApp.getActiveSheet(),
range,
values_array;
range = sheet.getRange('A2:A12');
values_array = range.getValues();
Logger.log(JSON.stringify(values_array));
}
Upvotes: 2