2017-02-06 17 views
1

좋습니다, stackoverflow.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 Issues'는 전적으로 보호되어야합니다.

어떻게해야합니까? 어떤 도움을 주시면 감사하겠습니다.

답변

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 ([보호되지 않음]); " –