SIDMISH
SIDMISH

Reputation: 166

How to make read only row in spreadsheet using Google Apps Script?

I have form response sheet, and I wanted to make some row to be in read only mode. How can I achieve it using Google Apps Script or any alternate methods are available for same.

Thank you!

Upvotes: 2

Views: 3571

Answers (1)

Dean Ransevycz
Dean Ransevycz

Reputation: 953

Two ways to solve this:

Apps Script

You want to use the Protection class of the Spreadsheet (documentation). This allows access to the built-in cell protection mechanisms. Here's the example form the documentation for making a range read-only:

 // Protect range A1:B10, then remove all other users from the list of editors.
 var ss = SpreadsheetApp.getActive();
 var range = ss.getRange('A1:B10');
 var protection = range.protect().setDescription('Sample protected range');

 // 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.
 protection.removeEditors(protection.getEditors());
 if (protection.canDomainEdit()) {
   protection.setDomainEdit(false);
 }
 // Now the range is not editable by anyone. 
 //  Just add yourself back to the editors list if necessary.
 protection.addEditor(Session.getEffectiveUser());

In the Sheets App

You can access the cell & range protection mechanisms from within the Sheets app via the Data menu. Select Data>Protect sheets and ranges..., then set the permissions in side-bar.

Upvotes: 2

Related Questions