2016-07-22 15 views
0

私はhere から情報を取り込んで、シート内のセル範囲を編集中に保護するスクリプトを作成しましたが、ユーザーがデータを入力できる領域も除外しています。私のスクリプトはこのように見えます。保護されたシートの中に予想されるが、私はまた私が制限したいのですが、この文書内の他の範囲を持っているように、これは確かに、この範囲のロックを解除しますvar unprotected = sheet.getRange('C9:D9');読み込む行でクラス保護スクリプト

function myFunction() { 
    // Protect the active sheet except B2:C5, then remove all other users from the list of editors. 
    var sheet = SpreadsheetApp.getActiveSheet(); 
    var protection = sheet.protect().setDescription('2016-07-21 Material Request Form Template'); 
    var unprotected = sheet.getRange('C9:D9'); 
    protection.setUnprotectedRanges([unprotected]); 
    // Ensure the current user is an editor before removing others. Otherwise, if the user's edit 
    // permission comes from a group, the script will throw an exception upon removing the group. 
    var me = Session.getEffectiveUser(); 
    protection.addEditor(me); 
    protection.removeEditors(protection.getEditors()); 
    if (protection.canDomainEdit()) { 
     protection.setDomainEdit(false); 
    } 
} 

。私は単純にこの行をコピーし、新しいセル範囲に貼り付けた場合は、複数の範囲がC9:D9と​​とA24:K24

、すなわちロックアウトすることができるように、私は入力するか、この行を変更することができますどのように、それは以前保護されていない範囲を上書きし、活性化し私はちょうどペーストした新しい行。

ありがとうございます。

答えて

0

あなたは1回の呼び出しで配列引数として範囲のすべてを渡す必要があり、複数の保護されていない範囲について:

var range1 = sheet.getRange("A1:A6"); 
var range2 = sheet.getRange("B1:B6"); 

protection.setUnprotectedRanges([range1, range2]); 

ご質問は切り替えているようだと、あなたが複数の範囲へのアクセスを制限する方法を求めて終わるように見えます、それらを保護しないでください。これを行うには、シート全体を保護し、関連する範囲を保護して、必要なものを達成してください。

関連する問題