简体   繁体   English

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

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

I am currently working on a script to automatically send an email when a cell is updated based on a specific value of cells. 我目前正在开发一个脚本,以便在根据特定的单元格值更新单元格时自动发送电子邮件。 Now I want to take those same values that I am emailed and populate them into a new spreadsheet and post a timestamp of when that row was updated. 现在我想采用与我通过电子邮件发送的相同值,并将它们填充到新的电子表格中,并发布该行更新时间的时间戳。 In the new SS it will be A(timestamp), B, C, D, E ( BE will be the data that is automatically emailed). 在新的SS中,它将是A(时间戳),B,C,D,E(BE将是自动通过电子邮件发送的数据)。

With the help of another user on here I was able to get the automated email system working. 在这里的另一个用户的帮助下,我能够使自动电子邮件系统正常工作。 I found several posts asking similar questions which I tried to piece together to see if I could get this working but I had no success. 我发现有几个帖子提出了类似的问题,我试图拼凑起来看看我是否可以开始工作,但我没有成功。 I kept running into blocks in the code because I don't know all the proper syntax for google-apps-scripts. 我一直在代码中遇到障碍,因为我不知道google-apps-scripts的所有正确语法。 I tried copyTo(), duplicateSheet(). 我试过copyTo(),duplicateSheet()。 But the problem is I only care about updating the one row at a time as the specific cell gets updated on the row. 但问题是我只关心在行上更新特定单元格时一次更新一行。 And all I found were posts about copying entire sheets of data onto a new spreadsheet. 我发现的所有内容都是关于将整张数据复制到新电子表格上的帖子。 I thought I would have to define it in the above and then add the copyTo() in the if statement but everytime I tried it the if statement broke and would get error message in the code. 我以为我必须在上面定义它然后在if语句中添加copyTo()但每次我尝试它时if语句都会破坏并在代码中得到错误消息。

(I also have an onEdit trigger in the project triggers) (我在项目触发器中也有一个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>" +
        })
  }
}

Basically I would love it if when column W, X, AE or AF get updated. 基本上我会喜欢它,如果列W,X,AE或AF得到更新。 on top of doing what it does currently of sending me an email of the information. 除了目前向我发送信息的电子邮件之外。 To also update all that information into a new row on a completely different spreadsheet with a timestamp of when that was edited so I can log it. 还要将所有信息更新到完全不同的电子表格中的新行,其中包含编辑时间的时间戳,以便我可以记录它。

I got this to work within my limited understanding of what your doing. 在我对你所做的事情的有限理解中,我得到了这个。

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.

相关问题 在编辑时将数据从一个电子表格复制到另一个电子表格 - Copy data from one spreadsheet to another on edit 如何在编辑时将数据从一个电子表格复制到另一个电子表格 - 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 如何使用应用程序脚本将值从一个子文件夹中的某些电子表格复制到另一电子表格 - How can I copy values from some spreadsheets that are in one subfolder to another spreadsheet with app script 使用 Google Apps 脚本将一个 Google 电子表格中的特定数据复制到另一个 Google 电子表格 - Copy Specific Data in one Google Spreadsheet to another Google Spreadsheet with Google Apps Script 如何将单元格中的单元格复制到不同电子表格中的工作表? - How do you copy cells from one spreadsheet to a sheet in a different spreadsheet? 如何使用谷歌应用脚本将一行从一个谷歌电子表格复制到另一个谷歌电子表格? - How to copy a row from one google spreadsheet to another google spreadsheet using google apps script? Google脚本会根据日期将范围从一个电子表格复制到另一个电子表格 - Google scripts copy range from one spreadsheet to another based on date Google电子表格将值从一行复制到另一张工作表 - Google spreadsheet copy values from one row to another sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM