简体   繁体   English

将活动行从一个工作表复制到另一个Google工作表

[英]copy active row From one sheet to another google sheets

I am having trouble copying a single row to a second sheet with google sheets. 我在将单行复制到带有Google表格的第二张表格时遇到问题。

I am using Google script editor to send automated email updates which works fine. 我正在使用Google脚本编辑器发送自动的电子邮件更新,效果很好。 However I am now trying to log each update from specific columns. 但是,我现在正尝试记录特定列中的每个更新。 I need all the information in the row to move with the cell that is edited. 我需要该行中的所有信息才能与被编辑的单元格一起移动。

Each Row is a separate job-site and I will have up to 30 concurrent job-sites going on at one time. 每行是一个单独的作业站点,我一次最多可以同时运行30个并发作业站点。 So the update may come in in cell "M3" or "M28" 因此更新可能会出现在单元格“ M3”或“ M28”中

What I am trying to do is capture only the row that is edited not the whole sheet. 我想做的是仅捕获已编辑的行,而不捕获整个工作表。 My current code is copying the whole sheet. 我当前的代码正在复制整个工作表。 I am drawing a blank on how to just define the single row as active and set it to a range. 我在如何仅将单行定义为活动并将其设置为范围上画了一个空白。

Here is what I have. 这就是我所拥有的。 I am no java script programmer but searching this site has gotten me this far. 我不是Java脚本程序员,但是搜索该站点已经使我走到了这一步。 Bare with the code is not perfect. 裸露的代码并不完美。

    function sendupdate() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getActiveSheet();
    var cell = ss.getActiveCell().getA1Notation();
    var row = sheet.getActiveRange().getRow();
    var cellvalue = ss.getActiveCell().getValue().toString();
    var recipients = '';
    var message = '';
    var techname = '';
    var branchname = '';
    var city = '';
    var state = '';
    var technumber = '';

    if(cell.indexOf('M')!=-1){ 
    message = sheet.getRange('B'+     sheet.getActiveCell().getRowIndex()).getValue()
    techname = sheet.getRange('N'+ sheet.getActiveCell().getRowIndex()).getValue()  
    branchname = sheet.getRange('H'+ sheet.getActiveCell().getRowIndex()).getValue()
    city = sheet.getRange('J'+ sheet.getActiveCell().getRowIndex()).getValue() 
    state = sheet.getRange('K'+ sheet.getActiveCell().getRowIndex()).getValue() 
    recipients = "(emailaddress";
    var subject = ' Update: ' +techname + '  ' + message + '  ' + city + ' ' + branchname +' ' ;
    var body =  ': ' + message + ' Technician: « ' + techname + ' » New Update: « ' + cellvalue + ' » has been posted to the  Update Sheet Visit ' + ss.getUrl() + ' to view the changes on row: ' + row + '';
    MailApp.sendEmail(recipients, subject, body);
    var target_sheet = ss.getSheetByName('Log')    
    var last_row = target_sheet.getLastRow();
    target_sheet.insertRowAfter(last_row);    
    sheet.getRange('A:P').copyTo(target_sheet.getRange('A'+(last_row+1)+':P'+(last_row+1)));
    }

    debugger

Get the Range of the active row by calling getRange(row, column, numRows ). 通过调用getRange(row, column, numRows )获取活动行的Range You can then use that range to copy it to the other sheets 然后,您可以使用该范围将其复制到其他工作表

Here is the code I added which made it work 这是我添加的代码,使其起作用

    var target_sheet = ss.getSheetByName('Log')    
    var last_row = target_sheet.getLastRow();
    var activeRow = sheet.getRange( row ,1, 1 ,16)
    target_sheet.insertRowAfter(last_row);    
    activeRow.copyTo(target_sheet.getRange('A'+(last_row+1)+':P'+(last_row+1)));

暂无
暂无

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

相关问题 谷歌脚本将特定列从一张纸复制到另一张纸上的最后一行 - Google Script to copy specific columns from one sheet to another sheets last row onEdit 将数据从一个 Google 工作表工作簿工作表复制到另一个工作簿 - Copy Data from One Google sheets Workbook Sheet to another Workbook 谷歌表格将格式从活动表格复制到其他所有表格 - google sheets copy formatting from active sheet to every other sheet 从母版工作表的最后一行复制数据,并将其粘贴到Google工作表中另一工作表的特定单元格 - Copy data from last row of master sheet and paste it in specific cells in another sheet in google sheets Google Sheets 将行复制并粘贴到另一个工作表中,然后从第一个工作表中删除内容 - Google Sheets copy and paste row into another sheet and then delete content from the first sheet 如何将一张工作表的值复制到另一张工作表Google工作表脚本 - How to copy the value of one sheet to another sheet Google sheets Script 将一行从一个Google表格电子表格复制到表单提交中的另一表格 - Copy a row from one Google Sheet Spreadsheet to Another on Form Submit Google 工作表脚本将数据集从一张工作表复制到另一张工作表的顶部(仅限值) - Google sheets script copy data sets from one sheet to another (values only) at the top of the sheet 根据条件和单元格值将行复制到 Google 表格上的另一张表格 - Copy row to another sheet on Google Sheets based on criteria and cell value 通过for循环谷歌表格脚本将行复制到另一张表格 - Copy row to another sheet via for loop google sheets script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM