简体   繁体   English

在编辑时将数据从一个电子表格复制到另一个电子表格

[英]Copy data from one spreadsheet to another on edit

I already try everthing but I cant make this work =/我已经尝试了一切,但我无法完成这项工作=/

I'm trying to copy data from one spreadsheet to other using setValues(), because link doesn't work for me.我正在尝试使用 setValues() 将数据从一个电子表格复制到另一个电子表格,因为链接对我不起作用。 I also need to keep the trigger on edit.我还需要保持触发器处于编辑状态。

So, I create one fuction called AddConvocacao, and always when have any change the script run.因此,我创建了一个名为 AddConvocacao 的函数,并且总是在有任何更改时运行脚本。

function addConvocacao(e){
  var linha = e.range.getRow(); //get the number of the line, where have edit
  var nome = e.source.getActiveSheet().getRange(linha,2).getValue(); //get the value of the field 

  var targetSheet = SpreadsheetApp.openById('1iQbZ7iB9ddc-HwLK9vG0eVEeWWqXKJZ0ry7U_Hm4SkQ') //open the other spreedsheet 
  var targetName = targetSheet.getSheetByName('Pac'); //open the tab
  var lastRow = targetName.getLastRow(); //count the last row in this tab
  lastRow = lastRow+1; //add 1
  
 targetName.getRange(lastRow, 2).setValue(nome); // set the value 
 // targetName.getRange(lastRow, 3).setValue(valorCol7);
 // targetName.getRange(lastRow, 5).setValue(dose);
 // targetName.getRange(lastRow, 6).setValue(diagnostico);
 // targetName.getRange(lastRow, 7).setValue(medico);
}

why dosen't work when I use on edit?为什么我在编辑上使用时不起作用?

Thanks so much!非常感谢! =) =)

I did it a little different I think.我觉得我做的有点不同。 I put checkboxes in column one and capture the value from column 2 and sent it to the other spreadsheet to the bottom of column 2我将复选框放在第一列并从第 2 列捕获值并将其发送到另一个电子表格到第 2 列的底部

function onMyEdit(e) {
  //e.source.toast('entry');
  const sh = e.range.getSheet();
  //Logger.log(JSON.stringify(e));
  if (sh.getName() == 'Sheet1' && e.range.columnStart==1 && e.value=="TRUE") {
    //e.source.toast('cond');
    const v = sh.getRange(e.range.rowStart, 2).getValue();
    var tss = SpreadsheetApp.openById(getGlobal('targetid'));
    var tsh = tss.getSheetByName('Sheet1');
    tsh.getRange(tsh.getLastRow() + 1, 2).setValue(v);
    e.range.setValue("FALSE");
  }
}

You must use an installable trigger to us openById();您必须对我们使用可安装的触发器 openById();

getGlobal(targetid) just gets a spreadsheet id you can replace that with the id getGlobal(targetid) 只是获取一个电子表格 id,您可以将其替换为 id

Also I limited the action to only one sheet and only when I set the checkbox to true.此外,我将操作限制为仅一张纸,并且仅当我将复选框设置为 true 时。 I reset it back to false in the code.我在代码中将其重置为 false。

You'll need to modify a few things to get it to work for you because when I'm doing the examples I do it my way.你需要修改一些东西才能让它为你工作,因为当我做例子时,我会按照我的方式去做。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在编辑时将数据从一个电子表格复制到另一个电子表格 - How to copy data from one spreadsheet to another on edit 将数据从一个电子表格复制到另一种保留格式且不使用公式 - Copy data from one Spreadsheet to another keeping format and without formulas 将多个工作表从一个电子表格复制到另一个电子表格 - Copy several sheets from one spreadsheet to another spreadsheet 我可以将数据从一个电子表格复制到新的电子表格吗? - Can I copy data from one spreadsheet to a new spreadsheet? Google脚本会根据日期将范围从一个电子表格复制到另一个电子表格 - Google scripts copy range from one spreadsheet to another based on date Google电子表格将值从一行复制到另一张工作表 - Google spreadsheet copy values from one row to another sheet 将一行从一个Google表格电子表格复制到表单提交中的另一表格 - Copy a row from one Google Sheet Spreadsheet to Another on Form Submit 将过滤后的范围从一个电子表格复制到另一个 - Google 应用脚本 - Copy filtered range from one spreadsheet to another - Google app script 使用 Google Apps 脚本将一个 Google 电子表格中的特定数据复制到另一个 Google 电子表格 - Copy Specific Data in one Google Spreadsheet to another Google Spreadsheet with Google Apps Script 如何使用谷歌应用脚本将一行从一个谷歌电子表格复制到另一个谷歌电子表格? - How to copy a row from one google spreadsheet to another google spreadsheet using google apps script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM