繁体   English   中英

我可以将数据从一个电子表格复制到新的电子表格吗?

[英]Can I copy data from one spreadsheet to a new spreadsheet?

我目前正在开发一个脚本,以便在根据特定的单元格值更新单元格时自动发送电子邮件。 现在我想采用与我通过电子邮件发送的相同值,并将它们填充到新的电子表格中,并发布该行更新时间的时间戳。 在新的SS中,它将是A(时间戳),B,C,D,E(BE将是自动通过电子邮件发送的数据)。

在这里的另一个用户的帮助下,我能够使自动电子邮件系统正常工作。 我发现有几个帖子提出了类似的问题,我试图拼凑起来看看我是否可以开始工作,但我没有成功。 我一直在代码中遇到障碍,因为我不知道google-apps-scripts的所有正确语法。 我试过copyTo(),duplicateSheet()。 但问题是我只关心在行上更新特定单元格时一次更新一行。 我发现的所有内容都是关于将整张数据复制到新电子表格上的帖子。 我以为我必须在上面定义它然后在if语句中添加copyTo()但每次我尝试它时if语句都会破坏并在代码中得到错误消息。

(我在项目触发器中也有一个onEdit触发器)

function sendNotification(e){ 

  var ss = e.source.getSheetByName('Datasheet'); //defines the source of 
where to look
  var cell = e.range.getA1Notation(); 
  var row = e.range.getRow(); //from the range gets the row(is important 
for calling the control owner and control ID on line 15 and 16)
  var col = e.range.getColumn(); //from the range gets the 
column(important when pulling specific columns of information)
  var cellvalue = e.range.getValue(); //this pulls whatever is inside of 
the cell. (so 'NAME' in column i)
  var subject = 'SUBJECT: '+ ss.getSheetName(); //tells the program what 
to put in the subject line of the email (ss.getSheetName() gets the name 
 of the tab of the data)
  var name = ss.getRange(row, 9).getValue(); //get column 9 for current 
row (column 9 is column i which is the control certifier)



  if (name === 'NAME' && (col === 23 || col === 24 || col === 31 || col 
=== 32) === true) {  //states: if the cell  in column i = TRUE, AND column 
(w)23, (x)24, (ae)31 OR (af)32 = changed/updated THEN execute command 
below
   var control = ss.getRange(row, 2).getValue(); //get value for column B 
in updated cell row
   var owner = ss.getRange(row, 8).getValue();   //get value for column H 
in updated cell row





    //line 21-35 is the email formatting
    //MailApp.sendEmail() sends the email if line 14 = TRUE
    // to: who the email is sent too
    //Subject = subject defined above
   //htmlBody = what is in the body of the paragraph sent


   MailApp.sendEmail({
      to: "EMAIL",
      subject: subject,
      htmlBody: "The following cell has been updated: <br><br>"+
      "<br><br>" + "The control is: " + control +
      ", <br><br>The owner is: " + owner +  
      "<br><br>The change was: " + cellvalue + "<br>" + 
      "<br><br>Thank you. <br><br><br><br>" +
        })
  }
}

基本上我会喜欢它,如果列W,X,AE或AF得到更新。 除了目前向我发送信息的电子邮件之外。 还要将所有信息更新到完全不同的电子表格中的新行,其中包含编辑时间的时间戳,以便我可以记录它。

在我对你所做的事情的有限理解中,我得到了这个。

function notify(e){ 
  var sh=e.range.getSheet();
  var dsh=e.source.getSheetByName('Sheet161');
  var name=sh.getRange(e.range.rowStart,9).getValue();
  var col=e.range.columnStart;
  //e.source.toast('Start');
  if (sh.getRange(e.range.rowStart,9).getValue()=='NAME' && sh.getName()=='Selection') {
    //e.source.toast('Flag1');
    if (col==23 || col==24 || col==31 || col==32) {
      //e.source.toast('Flag2'  +  sh.getRange(e.range.rowStart,col).getValue());
      if(sh.getRange(e.range.rowStart,col).getValue()==true) {
        //e.source.toast('Flag3');
        var control=dsh.getRange(e.range.rowStart, 2).getValue();
        var owner=dsh.getRange(e.range.rowStart, 8).getValue();
      }
    }
    var html="The following cell has been updated: <br><br>"; 
    html+="The control is: " + control + ", <br><br>The owner is: ";
    html+=owner + "<br><br>The change was: " + e.value + "<br>" + "<br><br>Thank you. <br><br><br><br>";
    //MailApp.sendEmail({to: "EMAIL",subject: subject,htmlBody:html});
    var userInterface=HtmlService.createHtmlOutput(html);
    SpreadsheetApp.getUi().showModelessDialog(userInterface,'data' );
  }
}

暂无
暂无

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

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