google apps脚本:删除和恢复保护 [英] google apps script: remove and restore protection

查看:50
本文介绍了google apps脚本:删除和恢复保护的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个电子表格,具有受保护工作表的每个人都可以编辑该电子表格,其中某些范围不受保护.

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.

推荐答案

似乎没有简单的方法,因为从菜单运行的功能始终以用户在键盘上"执行.

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

一种解决方法是将网络应用发布为始终以"所有者.然后,此Web应用程序将写入 doPost()上的受保护范围.然后,链接到菜单UI的功能将使用 UrlFetch 以发布到已发布的Web应用程序.您还可以使用带有密码/随机生成的数字的一些基本身份验证来拒绝来自脚本外部的请求.

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.

这篇关于google apps脚本:删除和恢复保护的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆