google apps script: remove and restore protection

不想你离开。 提交于 2021-01-28 18:33:12

问题


I have a spreadsheet that is editable by everyone with a protected sheet with some ranges unprotected.

I want cells that can be altered by a script run by any user (from a menu), but not manually.

When I run the script not as the owner it gives an error message when I try to temporarily remove the protection.


回答1:


There seems to be no easy way to do this, because functions run from the menu is always executed as "user at the keyboard".

One workaround is to publish a Web App to always "Execute as" Owner. This web app will then write to protected ranges on doPost(). The function linked to Menu UI will then use UrlFetch to POST to the published Web App. You can also use some basic authentication with a password/randomly generated numbers to reject requests from outside your script.

Also, If you don't trust editors not to mess with your bound script, It's better to publish it as a private add-on, where the source code is not easily accessible.



来源:https://stackoverflow.com/questions/53010743/google-apps-script-remove-and-restore-protection

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