简体   繁体   中英

Google Sheets - Sending Row to Another Spreadsheet

Written a Google Sheet where when a button is pressed a collated row of data is sent to a different Google Sheet. It was launched six months ago among colleagues that have full permissions to both sheets. The reason for this post was that 1 in 10 submissions goes missing and never arrives to be added to the secondary Google Sheet. Thus wondering if anyone had any ideas as to if there was an issue with my code.

sh.getRange("j7").setValue('=now()');
var range = sh.getRange('J7:R7'); //Fixed range of where the row/data is collated
var data = range.getValues();

var tss = SpreadsheetApp.openById('SHEET ID');
var ts = tss.getSheetByName('Main'); 

ts.getRange(ts.getLastRow()+1,1,1,9).setValues(data);

Many thanks for any ideas...

Try this:

function lfunko() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Enter Your Sheet Name");
  sh.getRange("J7").setFormula('=now()');
  var range = sh.getRange('J7:R7'); 
  var data = range.getValues();
  var tss = SpreadsheetApp.openById('SHEET ID');
  var ts = tss.getSheetByName('Main');
  ts.getRange(ts.getLastRow() + 1, 1, data.length, data[0].length).setValues(data);
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM