Simon Breton
Simon Breton

Reputation: 2876

Copy and Past multiple rows. Ljava.lang.Object response

I'm writing a little script to automatically copy/past some data from one sheet to another sheet.

I've come up with the following script :

function test() {
var sheet = SpreadsheetApp.openById('1sLVRDzzOopFQrXLNtAYKfyBfJthCkjvK8xe_PtOmso0').getSheetByName('Sheet1');
var numRows = sheet.getLastRow()-1;

     for(var i = 0; i < numRows; i++) {
  // Dispatching Data
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2")
  var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1")

  var data1 = sheet.getRange('Sheet1!A2:G2').getValues();

  sheet.appendRow([data1]);
  ss.deleteRow(2)
  }
} 

It's working perfectly fine but return me the following response :

Ljava.lang.Object response... for each row.

What should I do ? thanks !

Upvotes: 1

Views: 956

Answers (1)

utphx
utphx

Reputation: 1295

If you want to use your script then the simple fix is to change:

sheet.appendRow([data1]);

to:

sheet.appendRow(data1[0]);

because you only want the 1 row.

However I'm not sure what the point of your for loop is? This might be a little cleaner:

function test() {
  var ss = SpreadsheetApp.openById('ID')
  var sheet1 = ss.getSheetByName("Sheet1")
  var sheet2 = ss.getSheetByName("Sheet2")
  var data1 = sheet1.getRange('Sheet1!A2:G2').getValues();
  sheet2.appendRow(data1[0]);
  sheet1.deleteRow(2)
} 

Upvotes: 2

Related Questions