1

Googleスクリプトのシート作成(保護の問題)

私は質問に直接飛びます。私はいくつかの個々のブックに正しい情報を(質問/インポート範囲を介して)提供する多くの情報を持つメインのワークブックを持っています。私は、毎週メインワークブックを更新し、次のコードで毎週、個々のワークブックのための新しいシートを作成します。このコードは、すべての個々のワークブックに二つの新しいシートを作成するには完璧に動作

function onOpen() { 
var ss = SpreadsheetApp.getActiveSpreadsheet(); 
var pasteSheet = [ {name: "Paste Sheet", functionName: "copySheet"}]; 
ss.addMenu("Copy to Spreadsheets", pasteSheet); 
} 

function copySheet() { 
var source = SpreadsheetApp.getActiveSpreadsheet(); 
var sheet = source.getSheets()[0]; 
var sheet2 = source.getSheets()[1]; 
var sourceFile = DriveApp.getFileById(source.getId()); 
var sourceFolder = sourceFile.getParents().next(); 
var folderFiles = sourceFolder.getFiles(); 
var thisFile; 

while (folderFiles.hasNext()) { 
    thisFile = folderFiles.next(); 
    if (thisFile.getName() !== sourceFile.getName()){ 
    var currentSS = SpreadsheetApp.openById(thisFile.getId()); 
    sheet.copyTo(currentSS); 
    sheet2.copyTo(currentSS); 
    currentSS.getSheets()[currentSS.getSheets().length-2].setName('W6'); 
    currentSS.getSheets()[currentSS.getSheets().length-1].setName('W6 ISSUES'); 
    }  
};  
} 

私の問題:私は、このスクリプトを実行する際にさまざまな方法で保護を組み込むよう取り組んできました。私が必要とするのは、個々のシートを保護することです(W6とW6の問題)。最初のW6はA3:A20の範囲を除いて完全に保護されている必要があります。ここでは、個々のシートの所有者に編集を許可する必要があります。 「W6問題」は完全に保護されるべきである。

これを行うにはどうすればいいですか?どんな助けもありがとう。

答えて

0

保護情報はここで見つけることができます:ここでは

https://developers.google.com/apps-script/reference/spreadsheet/protectionは「W6問題」

var W6issues = currentSS.getSheets()[currentSS.getSheets().length-1].setName('W6 ISSUES'); 
var protection = W6issues.protect().setDescription('Sample protected sheet'); 

を保護するためのサンプルであるため.remove()の使用、その後「W6」のために同じことを行うと、あなたが保護したくない範囲https://developers.google.com/apps-script/reference/spreadsheet/protection#remove

+0

ありがとう! 100回のようなそのページにあり、最終的に私の答えが見つかりました '' // B2:C5以外のアクティブなシートを保護してから、エディタのリストから他のすべてのユーザを削除してください。 var sheet = SpreadsheetApp.getActiveSheet(); var protection = sheet.protect()。setDescription( 'サンプル保護シート'); var unprotected = sheet.getRange( 'B2:C5'); protection.setUnprotectedRanges([unprotected]); '' –

関連する問題