Google sheets 谷歌脚本表创建(保护问题)
好的,stackoverflow 我会直接开始我的问题。我有一个主工作簿,其中包含大量信息(通过查询/导入)向多个单独的工作簿提供正确的信息。我每周更新主工作簿,并每周使用以下代码为各个工作簿创建新工作表:Google sheets 谷歌脚本表创建(保护问题),google-sheets,google-spreadsheet-api,protection,Google Sheets,Google Spreadsheet Api,Protection,好的,stackoverflow 我会直接开始我的问题。我有一个主工作簿,其中包含大量信息(通过查询/导入)向多个单独的工作簿提供正确的信息。我每周更新主工作簿,并每周使用以下代码为各个工作簿创建新工作表: function onOpen() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var pasteSheet = [ {name: "Paste Sheet", functionName: "copySheet"}]; ss.addMe
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问题)。除了A3:A20范围外,W6中的第一个应该受到完全保护,在这一范围内,我需要允许各个页面的所有者进行编辑。”W6问题应得到完全保护
我将如何着手实现这一点?如有任何帮助,将不胜感激。保护信息可在此处找到: 下面是一个保护“W6问题”的示例
对“W6”执行相同的操作,然后对不需要保护的范围使用.remove(),可以在此处找到保护信息: 下面是一个保护“W6问题”的示例
对“W6”执行相同的操作,然后对不需要保护的范围使用.remove(),谢谢!在该页面上浏览了100次,终于找到了我的答案``//保护除B2:C5之外的活动工作表,然后从编辑器列表中删除所有其他用户。var sheet=SpreadsheetApp.getActiveSheet();var protection=sheet.protect().setDescription('Sample protected sheet');var unprotected=sheet.getRange('B2:C5');protection.setUnprotectedRanges([unprotected])``非常感谢。在该页面上浏览了100次,终于找到了我的答案``//保护除B2:C5之外的活动工作表,然后从编辑器列表中删除所有其他用户。var sheet=SpreadsheetApp.getActiveSheet();var protection=sheet.protect().setDescription('Sample protected sheet');var unprotected=sheet.getRange('B2:C5');protection.setUnprotectedRanges([unprotected])``
var W6issues = currentSS.getSheets()[currentSS.getSheets().length-1].setName('W6 ISSUES');
var protection = W6issues.protect().setDescription('Sample protected sheet');