简体   繁体   中英

Google Spreadsheet User permission with Google Apps Script

I am not able to replicate the result of these actions (see pictures) WITH GOOGLE APPS SCRIPT CODE.

Here are the actions:

Open a SpreadSheet with Google Spreadsheets

Right click -> Protect Range...

Click on this

在此处输入图片说明

Then click on this

在此处输入图片说明

And

在此处输入图片说明

I had NO success by trying this code:

SpreadsheetApp.addEditor('theEmailThatIWantToEnabled@email.com');

Here the solution of this problem.

In my specific case the permissions were "by sheets" and NOT "by ranges" .

So here a small working code:

var ss = SpreadsheetApp.getActive();
var protections = ss.getProtections(SpreadsheetApp.ProtectionType.SHEET);
for (var i = 0; i < protections.length; i++) {
      protections[i].addEditor('theEmailYouWantEnabled@email.com');      
    }

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