[英]Google sheets copy whole sheet to another
我有一個谷歌電子表格,其中包括幾張從各種來源動態維護的表格。 稱它們為 Dynamic_data1 和 Dynamic_data2。
對於這些動態表中的每一個,都有一個配套的 static 表。 我們稱它們為 Static_data1 和 Static_data2。
我定期需要對這兩對工作表執行以下操作,我一直在手動執行:
然后對 Dynamic_data2/Static_data2 重復該過程
無論存在多少行或列,它始終是整個工作表。
手動執行此操作很好,但我發現我需要自動化它。 我做了一點腳本,不多,所以我不是專家。
我不禁認為這應該是一個簡單的腳本工作。 但是,我無能的谷歌搜索沒有找到我可以適應的東西。 我會很感激你的建議。
嘗試這樣的事情:
function copyAll() {
const ss=SpreadsheetApp.getActive();//Spreadsheet with spreadsheet id's
const sh=ss.getSheetByName('FromToList');//sheet with spreadsheet id's
const idA=sh.getRange(2,1,sh.getLastRow()-1,sh.getLastColumn()).getValues().map((r)=>{
return {from:r[0],to:r[1]};//FromToList is a sheet with from id's in columnA and to id's in columnB
});//tested down to here the rest is up to you. I recommend not unleashing this on real spreadsheets until after you have thoroughly tested it.
idA.forEach(obj=>{
let fss=SpreadsheetApp.openById(obj.from);//from Spreadsheet
let fshts=fss.getSheets();//from sheets
let tss=SpreadsheetApp.openById(obj.to);//to Spreadsheet
let tshts=tss.getSheets();//to sheets
fshts.forEach(fsh=>{
fsh.copyTo(tss);//copy all from sheets to to spreadsheet
});
tshts.forEach(tsh=>{
tss.deleteSheet(tsh);//delete all original to sheets in to spreadsheet
});
});
}
注:function 未經測試
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.