简体   繁体   中英

Can a script edit a protected range or sheet?

I'm using a script to copy and paste some data with is filled by a couple of users without permission to edit only one line, the others ranges are protected from edit by these users.

The script copies the data from one sheet to another and both sheets are entirely protected, except by two editors who can edit anything. This same script is triggered on a time-based trigger when no one is working on this spreadsheet.

The question is: A script is able to edit a protected sheet or range?

Here is the code (just in case):

function CopyDaily() {
  var ss = SpreadsheetApp.openById('1olKDp').getSheetByName('Produtos vendidos'); //Seleciona a planilha DE ONDE os dados devem ser copiados
  var sss= SpreadsheetApp.openById('1olKDp').getSheetByName('BD Produtos vendidos'); //Seleciona a planilha PARA ONDE os dados devem ser copiados
  var LastRow1 = SpreadsheetApp.openById('1olKDp').getSheetByName('BD Produtos vendidos').getLastRow() + 1;
  var LastRow2 = SpreadsheetApp.openById('1olKDp').getSheetByName('BD Produtos vendidos').getLastRow() + 6;
  Logger.log(ss.getName());
  ss.getRange('A2:S7').copyTo(sss.getRange('A' + LastRow1 + ':S' + LastRow2), {contentsOnly:true})
}

function addTrigger() {
  var everyDay = ScriptApp.newTrigger("CopyDaily")
  .timeBased() //Define o tipo da trigger: Baseada em hora.
  .everyDays(1) //Frequencia de dias: a cada 1 dia.
  .atHour(12) //Em qual hora: 1 am.
  .create(); //Cria a trigger baseada nos parametros acima.
}

That depends, yes, a script is able to edit a protected range, what matters is who runs the script. The person (account) running the script must have edit permission on the protected range. If the account running the script does not have edit permission on the protected range then the code will throw an exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM