[英]How do I pull All data in one Google Sheet to another Google Sheet Tab using Google App Script?
My manager and I are stuck!我和我的经理被困住了!
What we are trying to do is pull all of the data from one google sheet to the first tab on another google sheet using google App Script.我们正在尝试做的是使用谷歌应用脚本将所有数据从一个谷歌工作表拉到另一个谷歌工作表上的第一个标签。 They are located in 2 separate folders as well.它们也位于 2 个单独的文件夹中。
We don't want to use =importrange() basic because it doesn't actively update the sheet!我们不想使用 =importrange() basic 因为它不会主动更新工作表! We are trying to automate our systems!我们正在努力使我们的系统自动化!
we tried using this and it was a no go.我们尝试使用它,但这是行不通的。
function CopyRange() {
var sss = SpreadsheetApp.openById('1vuqVDFLYc0pee0qITCQoL6ZXAOlzVl5Efg88F8mA39I'); //replace with source ID
var ss = sss.getSheetByName('Bob Swope - Flow'); //replace with source Sheet tab name
var range = ss.getRange('A2:AL1000'); //assign the range you want to copy
var data = range.getValues();
var tss = SpreadsheetApp.openById('17SZH2yKWuD1fonf-hOV1bpUumuOf5S24NI_V2Q0ITWo'); //replace with destination ID
var ts = tss.getSheetByName('input'); //replace with destination Sheet tab name
}
function movingData() {
var sss=SpreadsheetApp.getActive();//assuming this script is contained within this spreadsheet other you might wish to use openById();
var dss=SpreadsheetApp.openById('SSID');//open destination spreadsheeet by id
var dsh=dss.getSheets()[0];//first sheet on the left
var shts=sss.getSheets();//array of all sheets
//loop through all sheets getting data and appending to dsh
shts.forEach(function(sh,i){
var v=sh.getDataRange().getValues();
dsh.getRange(dsh.getLastRow()+1,1,v.length,v[0].length).setValues(v);
});
}
Class SpreadsheetApp 类电子表格应用程序
Assuming that you might wish to exclude some sheets from the source.假设您可能希望从源中排除一些工作表。 Then something like this might be useful.那么这样的事情可能会有用。
function movingData() {
var exclA['Sheetnames','To','Exlude']
var sss=SpreadsheetApp.getActive();
var dss=SpreadsheetApp.openById('SSID')
var dsh=dss.getSheets()[0];
var shts=sss.getSheets();
shts.forEach(function(sh,i){
if(exclA.indexOf(sh.getName())==-1) {
var v=sh.getDataRange().getValues();
dsh.getRange(dsh.getLastRow()+1,1,v.length,v[0].length).setValues(v);
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.