2017-03-01 8 views
0

私はGoogleスプレッドシートで作業していますが、現在のファイルの設定された個数のコピーを作成し、各コピーに次の名前を付けるスクリプトを作成しようとしていますある範囲内の名前のリストから、それらのファイルを前のスクリプトによって作成されたフォルダに配置します。私はそれがすべての作業を得ることができたが、最初のファイル(6つのうち、可能なはるかに)と私は間違っていることを把握することはできません。 Here's a copy of the sheet。また、ドキュメントのコピーを作成するための別のバージョンもありますが、数十枚のコピーを作成しているエンドユーザーのプロセスを合理化しようとしています。Google App Scripts - 範囲の名前のフォルダにファイルをコピーする

ありがとうございました!あなたは正しい軌道に乗っている

function createcopies2() { 
var ss = SpreadsheetApp.getActiveSpreadsheet(); 

// Get the range of cells that store necessary data. 
var CoachNames = ss.getRangeByName("CoachNames"); 

var CoachObjects = CoachNames.getValues(); 

var schoolNames = ss.getRangeByName("SchoolNames"); 

var SchoolObjects = schoolNames.getValues(); 

var id = ss.getId(); 
// The next variable gets a value that counts how many CoachNames there are in the spreadsheet 
var coaches = ss.getRangeByName("Coaches"); 

var numcoaches = coaches.getValue(); 

//here's the function 
for(i=0; i<numcoaches; i++){ 

var drive=DriveApp.getFileById(id); 

var name=CoachObjects[i].toString(); 

var folder=DriveApp.getFoldersByName(SchoolObjects[i]).next(); 

var folderid=folder.getId(); 

var folder2=DriveApp.getFolderById(folderid) 
if(folder) { 
drive.makeCopy(name, folder2)} 
else{ 
drive.makeCopy(name); 
} 

return; 
} 
} 

答えて

0

はここでスクリプトです。 私は説明を、以下のあなたを変更した:あなたはこの

のようなステートメントを使用します個々の値にアクセスするにgetValues

//The below statements a 2D dimensional array. 

var CoachObjects = CoachNames.getValues(); 

から2次元配列を取得するので、私は、コードを修正

function createcopies2() { 
var ss = SpreadsheetApp.getActiveSpreadsheet(); 

// Get the range of cells that store necessary data. 
var CoachNames = ss.getRangeByName("CoachNames"); 
//The below statements a 2D dimensional array. 
//To access the individual value you will have a statement like this 
//CoachObjects[0][0],CoachObject[1][0],[2][0] ..., down the row 
var CoachObjects = CoachNames.getValues(); 

var schoolNames = ss.getRangeByName("SchoolNames"); 
//The below statements a 2D dimensional array. 
var SchoolObjects = schoolNames.getValues(); 

var id = ss.getId(); 
// The next variable gets a value that counts how many CoachNames there are in the spreadsheet 
var coaches = ss.getRangeByName("Coaches"); 

var numcoaches = coaches.getValue(); 
//Moved the below statement out of the loop 
// Baceause you are using the same file 
var drive=DriveApp.getFileById(id); 
//here's the function 
for(i=0; i<numcoaches; i++){ 
var name=CoachObjects[i][0].toString(); 

var folder=DriveApp.getFoldersByName(SchoolObjects[i][0]).next(); 

var folderid=folder.getId(); 

var folder2=DriveApp.getFolderById(folderid) 
if(folder) { 
drive.makeCopy(name, folder2)} 
else{ 
drive.makeCopy(name); 
} 

return; 
} 
} 

`CoachObjects[0][0]` 
CoachObjects[1][0] 
.......  [2][0] ... 
down the row 

はまた、これらは、コードの冗長行であります

var folder2=DriveApp.getFoldersByName(SchoolObjects[i][0]).next(); 
関連する問題