Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sheet.getRange throwing signature mismatch exception when not using A1 notation

I'm writing a script on a Google Sheet that will be interacting with Google Map's Geocoding service.

The following code works correctly.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var header_v = ss.getRange("1:1").getValues();

However, later on in my function, I call Sheet.getRange() again using the Sheet.getRange(number, number, number, number) method:

var target_range = ss.getRange(1, ss.getLastColumn()+1, ss.getLastRow(), 10);

throws the following exception:

Exception: The parameters (String,number,number,number) don't match the method signature for Spreadsheet.getRange.

I've tried substituting the first parameter with a variable I know to be a number, to the same effect.

This is the function in its current state.

function geocode() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var header_v = ss.getRange("1:1").getValues();
  
  var col_indxs = {
    name : header_v[0].indexOf("restaurant_name"),
    address : header_v[0].indexOf("address")
  }

  var target_range = ss.getRange(1, ss.getLastColumn()+1, ss.getLastRow(), 10);
  Logger.log(target_range.getA1Notation());
}
like image 566
Benjamin Didur Avatar asked Aug 23 '19 21:08

Benjamin Didur


1 Answers

Resolved this myself.

var ss = SpreadsheetApp.getActiveSpreadsheet();

Returns a Spreadsheet, however the getRange(number, number, number, number) is a member of the Sheet class.

var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

Solved my problem.

like image 163
Benjamin Didur Avatar answered Oct 20 '22 17:10

Benjamin Didur