.setValue()不一致适用于Google表格脚本 [英] .setValue() Not Consistently Working for Google Sheets Script

查看:85
本文介绍了.setValue()不一致适用于Google表格脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在用我在Google表格中编写的一段脚本挣扎。脚本的目的是监视给定单元格的输入值(来自键盘)并验证输入是否遵循数据输入标准。

例如,所有输入值必须遵循标准 XX-XX-X 。例如, A5-03-1 是可以接受的,而 B555-01-1 不是。 (第一个组件是4位而不是2)。当输入值不符合标准时,我使用 .setValue()命令擦除条目...

  Sheet.getRange(active cell).setValue(); 

也遵循 .setValue()通过消息框:

  Browser.msgBox(Expecting format''XX-XX-X''。\\ n请重新输入数据。); 

这段代码的逻辑语句工作正常。什么是不正常工作是 .setValue()。有时会根据需要擦除条目,其他时间则保留无效条目。但是,始终消息框显示正确。这两个活动都在相同的逻辑测试中。



此外,我已授予包含 setValue() 。但是,我每天收到此表的错误电子邮件,错误信息是执行该操作需要授权。

最后 - 我有其他用途将数据输入到此工作表中。所有用户都已授予访问脚本的权限。

解决方案

我不知道为什么 setValue() 函数不起作用,但改为在使用 getRange() clear() $ c>。


I've been struggling with a piece of script I wrote in a Google Sheet. The purpose of the script is to monitor the input value (from the keyboard) for a given cell and validate that the input follows a data entry standard.

For example, all input values must follow the standard XX-XX-X. As an example, A5-03-1 is acceptable, whereas B555-01-1 is not. (The first component is 4 digits instead of 2.) When the input value does not follow the standard, I use a .setValue() command to erase the entry...

Sheet.getRange(active cell).setValue("");

The .setValue() is also followed by a message box:

Browser.msgBox("Expecting format ''XX-XX-X''. \\n Please re-enter data.");

The logical statements for this code are working fine. What isn't working fine is .setValue(). Sometimes it erases the entry as desired, other times the invalid entry remains. However, the message box always shows appropriately. Both activities are in the same logical test.

Furthermore, I have granted Authorization to the script containing setValue(). But I get daily e-mails of errors for this sheet with errors along the line of "Authorization is required to perform that action."

Lastly--I have other uses inputting data into this sheet. All users have granted access to the script.

解决方案

I'm not sure why the setValue() function isn't working, but instead, try using clear() after you use getRange().

这篇关于.setValue()不一致适用于Google表格脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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