Google apps script 谷歌表单保护-基本需求赢得';行不通

Google apps script 谷歌表单保护-基本需求赢得';行不通,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我有一个基本的问题,一直在绞尽脑汁想弄明白 我想要一个谷歌工作表,以查看只有任何人与链接。 我希望能够作为所有者编辑任何内容(duh) 我想保护一个表,除了某些单元格(比如A1)是可编辑的,并添加一个谷歌帐户(比如A1)的人george@gmail.com)所以他们只能编辑A1 我所有的尝试都导致匿名用户只能根据需要查看,但是george@gmail.com可以编辑每个单元格,但不限于A1 我可能做错了什么,还是这种情况根本不可能 我尝试过许多指南,包括: 谢谢 试试这个。我在我的样本表上设置

我有一个基本的问题,一直在绞尽脑汁想弄明白

我想要一个谷歌工作表,以查看只有任何人与链接。 我希望能够作为所有者编辑任何内容(duh) 我想保护一个表,除了某些单元格(比如A1)是可编辑的,并添加一个谷歌帐户(比如A1)的人george@gmail.com)所以他们只能编辑A1

我所有的尝试都导致匿名用户只能根据需要查看,但是george@gmail.com可以编辑每个单元格,但不限于A1

我可能做错了什么,还是这种情况根本不可能

我尝试过许多指南,包括:


谢谢

试试这个。我在我的样本表上设置共享给任何有链接的人都可以查看,然后添加了电子邮件地址,可以编辑。电子邮件地址的用户可以编辑“A1” 当然,我可以编辑所有内容

function protectionTest(){
 // Protect the active sheet except A1, then remove all other users from the  list of editors.
 var sheet = SpreadsheetApp.getActiveSheet();
 var protection = sheet.protect().setDescription('Sample protected sheet');
 var unprotected = sheet.getRange('A1');
 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);
 }}
这需要一段时间,但这将识别彩色范围并取消对它们的保护。设置可以如上所述进行编辑

 function cellsToUnprotect(){
 //Find cells of specific color and create array of ranges.
 var ss = SpreadsheetApp.getActiveSpreadsheet()
 var sheet = ss.getSheetByName("Sheet1")// Change Sheet Name as needed.
 var rng = sheet.getRange("A1:C10").getBackgrounds()// Adjust Range as  needed.
 var arrayBG=[]
{
  for(var i=0;i<rng.length;i++){
  for(var j=0;j<rng[1].length;j++){
  //if(rng[i][j] != "#ffffff"){ //Any background color not equal to white. I  prefer this.
  if(rng[i][j] == "#ffff00"){ //background color defined ("#ffff00" is  yellow)
  var r=i+1
  var c=j+1
  var range=sheet.getRange(r, c)
  arrayBG.push(range)
    }}}
  unprotect(arrayBG)
  }}

function unprotect(arrayBG){
//Protect Sheet1 and unprotect ranges in passed array.
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet = ss.getSheetByName("Sheet1") // Change Sheet Name as needed.
var protection = sheet.protect().setDescription('Sample protected sheet');
protection.setUnprotectedRanges(arrayBG);
// 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);
}}
函数cellsToUnprotect(){
//查找特定颜色的单元格并创建范围数组。
var ss=SpreadsheetApp.getActiveSpreadsheet()
var sheet=ss.getSheetByName(“Sheet1”)//根据需要更改工作表名称。
var rng=sheet.getRange(“A1:C10”).getBackgrounds()//根据需要调整范围。
var arrayBG=[]
{

对于(var i=0;i请尝试此操作。我在示例工作表上设置共享给任何具有可查看链接的人,然后使用可编辑功能添加电子邮件地址。电子邮件地址的用户可以编辑“A1” 当然,我可以编辑所有内容

function protectionTest(){
 // Protect the active sheet except A1, then remove all other users from the  list of editors.
 var sheet = SpreadsheetApp.getActiveSheet();
 var protection = sheet.protect().setDescription('Sample protected sheet');
 var unprotected = sheet.getRange('A1');
 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);
 }}
这需要一段时间,但这将识别颜色范围并取消对它们的保护。设置可以如上所述进行编辑

 function cellsToUnprotect(){
 //Find cells of specific color and create array of ranges.
 var ss = SpreadsheetApp.getActiveSpreadsheet()
 var sheet = ss.getSheetByName("Sheet1")// Change Sheet Name as needed.
 var rng = sheet.getRange("A1:C10").getBackgrounds()// Adjust Range as  needed.
 var arrayBG=[]
{
  for(var i=0;i<rng.length;i++){
  for(var j=0;j<rng[1].length;j++){
  //if(rng[i][j] != "#ffffff"){ //Any background color not equal to white. I  prefer this.
  if(rng[i][j] == "#ffff00"){ //background color defined ("#ffff00" is  yellow)
  var r=i+1
  var c=j+1
  var range=sheet.getRange(r, c)
  arrayBG.push(range)
    }}}
  unprotect(arrayBG)
  }}

function unprotect(arrayBG){
//Protect Sheet1 and unprotect ranges in passed array.
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet = ss.getSheetByName("Sheet1") // Change Sheet Name as needed.
var protection = sheet.protect().setDescription('Sample protected sheet');
protection.setUnprotectedRanges(arrayBG);
// 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);
}}
函数cellsToUnprotect(){
//查找特定颜色的单元格并创建范围数组。
var ss=SpreadsheetApp.getActiveSpreadsheet()
var sheet=ss.getSheetByName(“Sheet1”)//根据需要更改工作表名称。
var rng=sheet.getRange(“A1:C10”).getBackgrounds()//根据需要调整范围。
var arrayBG=[]
{

对于(var i=0;i很抱歉,我花了这么长时间才回答,我正在休假。这将处理多张工作表。如果这对您有效,请批准回答

function cellsToUnprotect(){
//Find cells of specific color and create array of ranges.
 var ss = SpreadsheetApp.getActiveSpreadsheet()
 var sheet = SpreadsheetApp.getActiveSheet();
 var sheetNameToWatch=[] //Array of Sheet names
 var names = ss.getSheets()
  for( j=0;j<names.length;j++) {
    var n= names[j].getSheetName();
      if(n!="Done"){ //If Sheet name not "Done" add to array. Change sheet  name to exclude sheets. 
       sheetNameToWatch.push(n)
      }}
   for(var k=0;k<sheetNameToWatch.length;k++){
      var rng =  ss.getSheetByName(sheetNameToWatch[k]).getRange("A1:C10").getBackgrounds()//  Adjust Range as needed.
      var arrayBG=[]
{
  for(var i=0;i<rng.length;i++){
  for(var j=0;j<rng[1].length;j++){
  //if(rng[i][j] != "#ffffff"){ //Any background color not equal to white. I   prefer this.
  if(rng[i][j] == "#ffff00"){ //background color defined ("#ffff00" is   yellow)
     var r=i+1
     var c=j+1
     var range=ss.getSheetByName(sheetNameToWatch[k]).getRange(r, c)
  arrayBG.push(range)
    }}}
  unprotect(arrayBG,sheetNameToWatch,k)
}}}

function unprotect(arrayBG,sheetNameToWatch,k){
 //Protect Sheet1 and unprotect ranges in passed array.
 var ss = SpreadsheetApp.getActiveSpreadsheet()
 var sheet = ss.getSheetByName(sheetNameToWatch[k]) // Change Sheet Name as needed.
var protection = sheet.protect().setDescription('Sample protected sheet');
protection.setUnprotectedRanges(arrayBG);
// 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);
}}
函数cellsToUnprotect(){
//查找特定颜色的单元格并创建范围数组。
var ss=SpreadsheetApp.getActiveSpreadsheet()
var sheet=SpreadsheetApp.getActiveSheet();
var sheetnametwatch=[]//工作表名称数组
var name=ss.getSheets()

对于(j=0;j对不起,我花了这么长时间才回答,我正在休假。这将处理多张表格。如果这对您有效,请批准答案

function cellsToUnprotect(){
//Find cells of specific color and create array of ranges.
 var ss = SpreadsheetApp.getActiveSpreadsheet()
 var sheet = SpreadsheetApp.getActiveSheet();
 var sheetNameToWatch=[] //Array of Sheet names
 var names = ss.getSheets()
  for( j=0;j<names.length;j++) {
    var n= names[j].getSheetName();
      if(n!="Done"){ //If Sheet name not "Done" add to array. Change sheet  name to exclude sheets. 
       sheetNameToWatch.push(n)
      }}
   for(var k=0;k<sheetNameToWatch.length;k++){
      var rng =  ss.getSheetByName(sheetNameToWatch[k]).getRange("A1:C10").getBackgrounds()//  Adjust Range as needed.
      var arrayBG=[]
{
  for(var i=0;i<rng.length;i++){
  for(var j=0;j<rng[1].length;j++){
  //if(rng[i][j] != "#ffffff"){ //Any background color not equal to white. I   prefer this.
  if(rng[i][j] == "#ffff00"){ //background color defined ("#ffff00" is   yellow)
     var r=i+1
     var c=j+1
     var range=ss.getSheetByName(sheetNameToWatch[k]).getRange(r, c)
  arrayBG.push(range)
    }}}
  unprotect(arrayBG,sheetNameToWatch,k)
}}}

function unprotect(arrayBG,sheetNameToWatch,k){
 //Protect Sheet1 and unprotect ranges in passed array.
 var ss = SpreadsheetApp.getActiveSpreadsheet()
 var sheet = ss.getSheetByName(sheetNameToWatch[k]) // Change Sheet Name as needed.
var protection = sheet.protect().setDescription('Sample protected sheet');
protection.setUnprotectedRanges(arrayBG);
// 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);
}}
函数cellsToUnprotect(){
//查找特定颜色的单元格并创建范围数组。
var ss=SpreadsheetApp.getActiveSpreadsheet()
var sheet=SpreadsheetApp.getActiveSheet();
var sheetnametwatch=[]//工作表名称数组
var name=ss.getSheets()

对于(j=0;jThanks Ed-使用代码的有趣方法。它确实有效,但我希望使用sheets gui,以便工作表所有者能够维护它,我有更多的单元格,但这可能对我有用。Ed,快速问题-我如何修改它以循环整个工作表,并为每个具有特定背景颜色的单元格设置保护你喜欢#000000?为谁设置保护什么?谁可能需要电子邮件地址。为george@gmail.com(就像我上面的例子)这样他们只能编辑某些单元格(代码中的sheet.getRange('A1')会这样做).A1将替换为一个循环,以获得具有特定十六进制颜色的所有单元格。我可以设置george@gmail.com使用工作表右上角的“共享”按钮。@ednelson感谢您的帮助!!!!当我在脚本编辑器中运行它时,会抛出此错误“找不到方法setUnprotectedRanges((类))。(第23行,文件“Code”)”。感谢Ed-使用代码的有趣方法。它确实有效,但我希望使用sheets gui,以便工作表所有者能够维护它,我有更多的单元格,但这可能对我有效。Ed,快速问题-我如何修改它以循环整个工作表,并为每个具有特定背景颜色的单元格设置保护,如e#000000?为谁设置保护到什么?谁可能需要电子邮件地址。为george@gmail.com(就像我上面的例子)这样他们只能编辑某些单元格(代码中的sheet.getRange('A1')会这样做).A1将替换为一个循环,以获得具有特定十六进制颜色的所有单元格。我可以设置george@gmail.com使用工作表右上角的“共享”按钮。@ednelson感谢您的帮助!!!!当我在脚本编辑器中运行它时,会抛出此错误“找不到方法setUnprotectedRanges((类))。(第23行,文件“Code”)”。这个问题不是关于与谷歌应用程序相关的编程,所以它与堆栈溢出无关。它属于打开。这个问题不是关于与谷歌应用程序相关的编程,所以它与堆栈溢出无关。它属于打开。谢谢-这很好,但我遇到了一些奇怪的问题。你愿意作为一个付费用户帮助我吗项目?如果是,请告诉我是否可以私下与您联系,以及如何与您联系-谢谢!!!!@markSS您可以通过ednelson@sbcglobal.netThank你-这很好,但我遇到了一些奇怪的问题。你愿意作为付费项目来帮助我吗?如果愿意,请让我知道我是否可以私下联系你,以及如何-谢谢!!@markSS你可以用机智告诉我ednelson@sbcglobal.net