[英]Comparing strings in google scripts
Trying to make a very basic function in google scripts. 尝试在Google脚本中实现非常基本的功能。 Basically, I want to read a value from cell J5 and increment the value in L5 until J5 says "Good!"
基本上,我想从单元格J5中读取一个值,并在L5中递增该值,直到J5说“好!”。 (which would happen based on other stuff in my spreadsheet).
(这将基于我的电子表格中的其他内容发生)。 I can't seem to test the string though.. when running, the code just seems to stop randomly or run forever (I also need the code to not touch the spreadsheet the moment it says "Good!", otherwise.. everything gets altered since the formulas run again).
我似乎无法测试该字符串..在运行时,代码似乎只是随机停止或永远运行(我还需要代码在显示“ Good!”的那一刻不要触摸电子表格,否则..一切都会得到由于公式再次运行而发生了变化)。
function makeSelections() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var testcell = ss.getRange('J5')
var testcellValue = testcell.getValue();
for (var i = 0; testcellValue != "Good!"; i++) {
ss.getRange('L5').setValue(i);
testcellValue = testcell.getValue();
}
}
EDIT: As zbnrg pointed out, it appears to be a problem with the spreadsheet being way too slow to keep up with the script. 编辑:正如zbnrg指出的那样,电子表格似乎太慢而无法跟上脚本,这似乎是一个问题。 Can anyone help with code to check a range (A2-A14) for no duplications (ie all unique entries)?
任何人都可以帮助代码检查范围(A2-A14)是否重复(即所有唯一条目)吗?
The recalculation of the "other stuff" in the spreadsheet is slower than the for-loop; 电子表格中“其他内容”的重新计算比for循环要慢; you might pause the calculation and let the spreadsheet recalculate.
您可以暂停计算并让电子表格重新计算。 Within the for-loop include:
在for循环中包括:
Utilities.sleep(1000); //1000 milliseconds for 1 sec, 2000 for 2, etc.
Javascript: fast, Google Spreadsheet recalc: slow, unpredictable Javascript:快速,Google Spreadsheet重新计算:缓慢,不可预测
Update for second part of question 问题第二部分的更新
Quick and dirty way to randomize a list without fussing with scripts: 快速而肮脏的方式来随机化列表而不用大惊小怪:
Use =rand(), this generates a random number between 0 and 1: 使用= rand(),这将生成一个介于0和1之间的随机数:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.