简体   繁体   English

Google表格/ AppScript - 将数据从一个工作表复制到另一个工作表

[英]Google Sheets/AppScript - Copying Data from one Sheet to Another

I want to create a button in my sheet that copies (or cuts and pastes) 'custom items' from one sheet (Daily Lab Orders) to the last row of the finished sheet (Finished 2016) once they're completed. 我想在我的工作表中创建一个按钮,在完成后,将一个工作表(每日实验室订单)中的“自定义项目”复制(或剪切和粘贴)到完成工作表的最后一行(2016年完工)。 I then want it to delete the row containing the 'custom item'. 然后,我希望它删除包含“自定义项”的行。 Logically, I thought I'd select the row, click the button, and the do this over and over for each 'custom item' that is finished. 从逻辑上讲,我以为我会选择行,单击按钮,然后对每个完成的“自定义项目”反复执行此操作。

The snag I've run into is that the script copies only cell A1. 我遇到的障碍是脚本只复制单元格A1。 It doesn't copy any other values along the first row and it will not copy anything below row 1. A1 is frozen and it is using the function NOW() to constantly update the time. 它不会复制第一行中的任何其他值,也不会复制第1行下面的任何值.A1被冻结,它使用函数NOW()来不断更新时间。

Below is my script. 下面是我的脚本。 Any assistance, please? 请帮忙吗? Thank you.* 谢谢。*

*The row deletion part of the script hasn't been written yet. *脚本的行删除部分尚未编写。

function myFunction() {

 var ss = SpreadsheetApp.openById('15yEY5ZX1HyOQFn-BkMXvksivADF3-8g9TnsIEI8aaL8'); //replace with source ID

 var source = ss.getSheetByName('Daily Lab Orders 2016'); //replace with source Sheet tab name
 var SRange = source.getActiveRange(); //assign the range you want to copy
 var SData = SRange.getValues();

 var target = ss.getSheetByName('Finished 2016'); //replace with destination Sheet tab name
 var last_row = target.getLastRow();
 var target_range = target.getRange("A"+(last_row+1)+":G"+(last_row+1))
 target.getRange(target.getLastRow()+1, 1, SData.length, SData[0].length).setValues(SData);


}

when you are using : 当你使用时:
var ss = SpreadsheetApp.openById('15yEY5ZX1HyOQFn-BkMXvksivADF3-8g9TnsIEI8aaL8');
You are open ing a spreadsheet, when you open a spreadsheet the activeRange is always A1 . 您打开电子表格,当您打开电子表格时,activeRange始终为A1
So, your script is acting normally. 所以,你的脚本正常运作。
If the function is wrote in the spreadsheet and for example if you are triggering it from a menu button then you could change the openById with getActive : 如果在电子表格中写入了该函数,例如,如果从菜单按钮触发该openById ,则可以使用getActive更改openById

var ss = SpreadsheetApp.getActive();
var source = ss.getActiveSheet();
var SRange = source.getActiveRange();

Here activeRange reflect the user selection, if you prefer to retrieve all the sheet content then you should change for : 这里activeRange反映用户选择,如果您想要检索所有工作表内容,那么您应该更改为:

 var ss = SpreadsheetApp.openById('15yEY5ZX1HyOQFn-BkMXvksivADF3-8g9TnsIEI8aaL8'); //replace with source ID
 var source = ss.getSheetByName('Daily Lab Orders 2016'); //replace with source Sheet tab name
 var SRange = source.getDataRange();

getDataRange take all the sheet content. getDataRange获取所有工作表内容。

暂无
暂无

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

相关问题 Google Sheets Script - 将数据范围从一张表复制到另一张表 - 整个范围不复制 - Google Sheets Script - Copying data range from one sheet to another - whole range not copying 将文本/数字从一张工作表复制到谷歌工作表中另一张工作表中已有的以下数据 - Copying text/numbers from one sheet to below data already in another sheet in google sheets 将数据从一个电子表格复制到另一个Google表格 - Copying data from one spreadsheet to another Google Sheet 将数据从一个 Google 工作表工作簿工作表复制到另一个工作簿 - Copy Data from One Google sheets Workbook Sheet to another Workbook Google表格根据单元格值从一张表格复制和粘贴到另一张表格 - Google Sheets Copying and Pasting from one sheet to another based on cell value Google 工作表脚本将数据集从一张工作表复制到另一张工作表的顶部(仅限值) - Google sheets script copy data sets from one sheet to another (values only) at the top of the sheet Google Appscript:将表格中的数据复制到最后一行中的另一张表格并清除表格 - Google Appscript: Copy Data from a Form Sheet to Another Sheet in Last Row and Clear Form 通过Appscript将行复制到另一张工作表 - Copying Rows to Another Sheet via Appscript 将数据从一张表传输到另一张表并删除谷歌表中的旧数据 - Transfer Data from one sheet to another and deleting old data in google sheets 使用 Google App 脚本将数据从一张工作表复制到另一张工作表时执行缓慢 - Slow Execution for Copying Data from One Sheet to Another Using Google App Script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM