使用 link 从文件发送值

Send values from file with link

我来这里是想问你一些关于 Google Sheets 宏的事情,
我想将 Google Sheet 文件中的信息发送到另一个文件。
我想,当我单击 link 时,它会将同一行的值发送到另一行

文件.

只需粘贴到 code.gs 和 运行 showSideBar 函数中。请注意侧边栏顶部提供的说明,一切都会正常进行。

function sendCurrentRow() {
  var tssid='target spreadsheet id';//put the target spreadsheet id here
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getActiveSheet();
  const rg=sh.getActiveRange();
  const row=sh.getRange(rg.getRow(),1,1,sh.getLastColumn()).getValues();
  const tss=SpreadsheetApp.openById(tssid);
  var tsh=tss.getSheetByName(sh.getName());
  if(!tsh) {
    var tsh=tss.insertSheet(sh.getName())
  }
  tsh.getRange(rg.getRow(),1,1,sh.getLastColumn()).setValues(row);  
}

function showSideBar() {
  var html='<p>If you haven put you target spreadsheet id in function sendCurrentRow() then do before pressing button below.</p><p>Place cursor on the row you wish to send and click button below.</p><br />'
  html+='<input type="button" value="Send" onClick="google.script.run.sendCurrentRow()" />';
  SpreadsheetApp.getUi().showSidebar(HtmlService.createHtmlOutput(html).setTitle('Send Current Row'));
}