好的,堆栈溢出。
我将直接进入我的问题。我有一个包含大量信息的主工作簿(通过。A查询/导入)将正确的信息发送到几个单独的工作簿。我每周更新主工作簿,并使用以下代码为各个工作簿创建新工作表:
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问题”应该受到完全的保护。
我该如何着手来实现这一点呢?任何帮助都将不胜感激。
发布于 2017-02-07 09:17:03
保护信息可在此处找到: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');对"W6“执行相同的操作,然后对不需要保护的范围使用.remove(),https://developers.google.com/apps-script/reference/spreadsheet/protection#remove
https://stackoverflow.com/questions/42074838
复制相似问题