[英]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.