2012-05-16 2 views
2

스크립트를 사용하여 특정 Google Apps 워크 시트를 잠그는 방법이 있습니까?스크립트를 사용하여 특정 Google Apps 워크 시트를 잠글 수 있습니까?

입력란에 입력 한 내용으로 현재 스프레드 시트의 이름을 바꾸는 코드가 있습니다.

// The code below will rename the active sheet to what you enter in the input box 
var myValue = Browser.inputBox("Enter: LastMonth - Year"); 
SpreadsheetApp.getActiveSpreadsheet().renameActiveSheet(myValue); 
SpreadsheetApp.getActiveSpreadsheet().getRange("A1").setValue(myValue); 

방금 ​​이름을 변경 한 워크 시트와 동일한 워크 시트를 잠글 수있는 위 코드에 추가 할 수있는 것은 무엇입니까? 그게 가능하니?

답변

5
// Enables sheet protection for this sheet 
var sheet = SpreadsheetApp.getActiveSheet(); 
var permissions = sheet.getSheetProtection(); 
permissions.setProtected(true); 
sheet.setSheetProtection(permissions); 

참조 스프레드 시트 서비스 - @ScampMichael 말했듯이 Class PageProtection

+0

내가 잠글 수 있습니다 :

var sheet = SpreadsheetApp.getActiveSheet(); sheet.protect(); 

가 보호를 해제하려면 다음과 같은 코드를 사용할 수있다 필요로 할 때 워크 시트를 편집 할 수있는 사용자 이름을 지정하거나 현재 로그인 한 사용자 만 사용하는 사용자 이름을 지정한 워크 시트? –

2

코드 아래, Spreadsheet Services에서 발견.

보호 된 시트를 편집 할 수있는 사용자 목록에 사용자를 추가합니다. Class PageProtection 이후

// Add the "[email protected]" user to the list of users who can edit this sheet 
var sheet = SpreadsheetApp.getActiveSheet(); 
var permissions = sheet.getSheetProtection(); 
permissions.addUser('[email protected]'); 
permissions.setProtected(true); 
sheet.setSheetProtection(permissions); 
0

는 현재 당신이 달성하기 위해 Class Protection를 사용할 수 있습니다되지 않습니다 같은 :

var protection = sheet.getProtections(SpreadsheetApp.ProtectionType.SHEET)[0]; 
if (protection && protection.canEdit()) { 
    protection.remove(); 
}