![](/img/trans.png)
[英]How to copy spreadsheet's sheet into another spreadsheet without creating a new sheet copy when using google sheet script?
[英]How can copy specifics sheet to another spreadsheet using google script
我有一個包含10個工作表和15個用戶登錄並對其進行修改的電子表格。 我只想從其他電子表格復制6張紙。
該腳本應為復印紙,以特定於另一個電子表格。
1)Source = XXXXXX我只想從Source復制表1,2,3,4,5,6,7,8到目標。 目標= YYYYY
注意:目標已經具有工作表1,2,3,4,5,6,7,8。 我需要更新目標電子表格,因為我使用它來制作報告。 我不能使用該程序,因為此報告是機密的。
2)該腳本需要從目標運行。
我閱讀了很多論壇,但沒有人提供有關“如何將工作表復制到另一個工作表”的通用腳本。 所有這些腳本都非常復雜,我是這個新手。
不適用
我認為這是一個工作表從一個電子表格到另一個工作表的簡單副本,但實際上我需要手動完成一次,但是我已經發出系統將工作表名稱更改為“ XXXXX副本”,但我的報告配置為使用特定的名稱,這就是為什么我需要使之成為可能。 我認為該腳本將對許多人有所幫助。
提前致謝。
你好
請您幫我調整此腳本以使其更有效。
function UpdateData() {
var source = SpreadsheetApp.openById('YYYYYY');
var sheet8 = source.getSheets()[8];
var sheet7 = source.getSheets()[7];
var sheet6 = source.getSheets()[6];
var sheet5 = source.getSheets()[5];
var sheet4 = source.getSheets()[4];
var sheet3 = source.getSheets()[3];
var sheet2 = source.getSheets()[2];
var sheet1 = source.getSheets()[1];
var destination = SpreadsheetApp.openById('ZZZZZZ');
sheet8.copyTo(destination).setName('Sheet8');
sheet7.copyTo(destination).setName('Sheet7');
Utilities.sleep(100);
sheet6.copyTo(destination).setName('Sheet6');
sheet5.copyTo(destination).setName('Sheet5');
Utilities.sleep(100);
sheet4.copyTo(destination).setName('Shee4');
sheet3.copyTo(destination).setName('Shee3');
Utilities.sleep(100);
sheet2.copyTo(destination).setName('Shee2');
sheet1.copyTo(destination).setName('Shee1');
SpreadsheetApp.flush();
}
只需從描述中查看docs: copyTo(spreadsheet)即可 :
將工作表復制到另一個電子表格。 目標電子表格可以是源電子表格。 新的電子表格的名稱為“ [原始電子表格名稱]的副本”
該方法還原復制的工作表,因此您可以對其進行重命名:
sourceSheet.copyTo(targetSpreadSheet).setName('somename');
希望您知道如何在JS中編寫循環...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.