代码已完成:@@ Master✔
对不起,我是google drive sdk中的绝对新手。
我正在尝试编写一个脚本,该脚本允许许多与更新相同的工作表。通过源电子表格(采用新格式)。问题是在旧表中,值在那里,必须在新表中的``源电子表格''(具有新格式)中。然后一次又一次地重复使用旧表。
我想到的脚本程序是
我会尽力帮助。
当前代码:
function UPDATE() {
//LEGEND: o=Old, ss=SpreadSheet, sss=SourceSreadSheet, s=Sheet, n=Name//
//---TAKE ALL OLD SPREADSHEEDS FROM FOLDER ---//
//replace it with Folder ID where the old spreadsheets are in
var folder=DriveApp.getFolderById('Folder ID')
//takes all files in the folder and sets the variable file
var files=folder.getFiles();
while (files.hasNext())
{
var file = files.next();
//---TAKE DATA---//
//replace with source ID
var o_ss=SpreadsheetApp.open(file);
//replace with source Sheet tab name 1 to as much as you want
var o_s_n1=o_ss.getSheetByName('tab name1');
var o_s_n2=o_ss.getSheetByName('tab name2'); //optional
//assign one ore more ranges you want to copy
var o_range1=o_s_n1.getRange('A1:A2');
var o_range2=o_s_n1.getRange('C1:C2'); //optional
//Copy the values
var o_data1=o_range1.getValues();
var o_data2=o_range2.getValues(); //optional
//---COPY DATA---//
//replace with destination ID
var sss_ss=SpreadsheetApp.openById('destination ID');
//replace with destination Sheet tab name
var sss_s=sss_ss.getSheetByName('tab name1');
//Area where to copy in the new sheet
sss_s.getRange('A1:A2').setValues(o_data1);
sss_s.getRange('C1:C2').setValues(o_data2); //optional
//closes the code until here first
SpreadsheetApp.flush();
//---DUPLIKATE SOURCE SHEET AND RENAME IT AND PUT IT IN THE DESTINATION FOLDER---//
//gets the sheet name from the old sheet
var o_ss_n=o_ss.getName();
//replace with destination Folder ID
var folder=DriveApp.getFolderById('Folder ID')
//Copy the destination sheet and name it like the old sheet
DriveApp.getFileById('destination ID').makeCopy(o_ss_n,folder);
}
}
答案 0 :(得分:1)
最后完成 @@ TheMaster
true