Google电子表格应用程序脚本-[如何使用此代码加快运行功能]
我想让它现在变得更快
我编写了一些脚本,制作了许多复制的约366张纸。但是,谷歌电子表格的运行时间有限。所以我必须等待并运行第二个功能。
复制和工作表名称更改代码。工作表名称为1月1日至12月31日,包括2月29日like [01.01] [01.02] [01.03] .... [02.29] ... [12.30] [12.31]
我正在等待切肉刀解决方案谢谢你的领导
function Sheets_Copying_with_Name(){
var source = SpreadsheetApp.getActiveSpreadsheet();
var sheet = source.getSheets()[0];
var Typing_Month =1;
var Typing_Day=1;
var MAX_Day = 31;
for (Typing_Month; Typing_Month< 13; Typing_Month++)
{
var destination = SpreadsheetApp.openById("Sheet ADDRESS");
if ((Typing_Month==1)||(Typing_Month==3)||(Typing_Month==5)||(Typing_Month==7)||(Typing_Month==8)||(Typing_Month==10)||(Typing_Month==12)) { MAX_Day=31; }
if ((Typing_Month==4)||(Typing_Month==6)||(Typing_Month==9)||(Typing_Month==11)) { MAX_Day=30; }
if ( Typing_Month==2) { MAX_Day=29;}
for( Typing_Day; Typing_Day < MAX_Day +1; Typing_Day++ )
{ if( (Typing_Month < 10) && (Typing_Day < 10)) { sheet.copyTo(destination).setName("0"+Typing_Month+".0"+Typing_Day);}
if( (Typing_Month < 10) && (Typing_Day > 9)) { sheet.copyTo(destination).setName("0"+Typing_Month+"."+Typing_Day);}
if( (Typing_Month > 9) && (Typing_Day < 10)) { sheet.copyTo(destination).setName(Typing_Month+".0"+Typing_Day);}
if( (Typing_Month > 9) && (Typing_Day > 9)) { sheet.copyTo(destination).setName(Typing_Month+"."+Typing_Day);}
}
Typing_Day = 1;
}
}
问题和解决方法:
修改的脚本:
function Sheets_Copying_with_Name(){
var destinationSpreadsheetId = "###"; // Please set the destinaton Spreadsheet ID.
var source = SpreadsheetApp.getActiveSpreadsheet();
var sheet = source.getSheets()[0];
var Typing_Month =1;
var Typing_Day=1;
var MAX_Day = 31;
// I modified below script.
var destination = SpreadsheetApp.openById(destinationSpreadsheetId);
var sourceSheet = sheet.copyTo(destination).setName("sourceSheet");
SpreadsheetApp.flush();
var sourceSheetId = sourceSheet.getSheetId();
var requests = [];
for (Typing_Month; Typing_Month< 13; Typing_Month++) {
if ((Typing_Month==1)||(Typing_Month==3)||(Typing_Month==5)||(Typing_Month==7)||(Typing_Month==8)||(Typing_Month==10)||(Typing_Month==12)) { MAX_Day=31; }
if ((Typing_Month==4)||(Typing_Month==6)||(Typing_Month==9)||(Typing_Month==11)) { MAX_Day=30; }
if ( Typing_Month==2) { MAX_Day=29;}
for( Typing_Day; Typing_Day < MAX_Day +1; Typing_Day++ ) {
if( (Typing_Month < 10) && (Typing_Day < 10)) {
requests.push({duplicateSheet: {sourceSheetId: sourceSheetId, newSheetName: "0"+Typing_Month+".0"+Typing_Day}});
}
if( (Typing_Month < 10) && (Typing_Day > 9)) {
requests.push({duplicateSheet: {sourceSheetId: sourceSheetId, newSheetName: "0"+Typing_Month+"."+Typing_Day}});
}
if( (Typing_Month > 9) && (Typing_Day < 10)) {
requests.push({duplicateSheet: {sourceSheetId: sourceSheetId, newSheetName: Typing_Month+".0"+Typing_Day}});
}
if( (Typing_Month > 9) && (Typing_Day > 9)) {
requests.push({duplicateSheet: {sourceSheetId: sourceSheetId, newSheetName: Typing_Month+"."+Typing_Day}});
}
}
Typing_Day = 1;
}
requests.push({deleteSheet: {sheetId: sourceSheetId}});
Sheets.Spreadsheets.batchUpdate({requests: requests}, destinationSpreadsheetId);
}
对于在Google表格中创建或转换为Google表格的电子表格,最多500万个单元格或18278列(ZZZ列)。>
参考: