Google Apps Script - Is it possible to allow change to some cell in Sheets only through GoogleAppScript?

百般思念 提交于 2020-06-16 23:51:13

问题


My making a catalog in Google SpreadSheet. My spreasheet has a table where the user can add information. This table is dynamically created through a Script that gets the data from the database sheet.

The user can edit some cells in the table and click on a button that saves the changes back into the database sheet.

I want to limit the cells he can edit manually, but I can´t protect theses cells, because there is a script that modifies it (since the table is dynamically generated through a script).

Is there a way to protect cells so that they can only be edit by a script?

I can not just protect some ranges, because it is the user that runs the script that modifies the cells. If I protect the ranges, the user can´t change the range either manually or using the script. I want a way to protect the range against manual input, but allow the script, that the user runs (not the spreadsheet owner), to change the cells.

Thank you


回答1:


Instead of using a bounded script use a stand alone script to create a web app that runs with the owner permissions. This because the bounded scripts runs this the permissions of the user that execute the script.

To help you user to execute the webapp, I think that you could create a user dialog or side panel that will display the link to the webapp.




回答2:


I have solved this issue by the following steps

printsht.getRange("A1:Q22").setDataValidation(null);

Do whatever processing in the range

printsht.getRange(1,1,22,17).setValues(prin);

After all the processing and setValues etc

// block editing after printing var cell = printsht.getRange( "A1:Q22"); var rule = SpreadsheetApp.newDataValidation().requireTextEqualTo('$$').setAllowInvalid(false).setHelpText("Do not edit in print sheet").build(); cell.setDataValidation(rule);

Now no one can edit the range manually. All the formula etc will work normally.

But, if the user is having edit rights, he can easily remove the validation from the system menu. So, it is not foolproof.



来源:https://stackoverflow.com/questions/40794448/google-apps-script-is-it-possible-to-allow-change-to-some-cell-in-sheets-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!