2.0在Google Apps脚本中被识别为20(2.0 is recognized as 20 on google apps script)

编程入门 行业动态 更新时间:2024-10-15 20:19:53
2.0在Google Apps脚本中被识别为20(2.0 is recognized as 20 on google apps script)

我正在尝试在Google电子表格上运行脚本。 以下是代码段:

var startRow = 2; var data = dataRange.getValues(); for (i in data) { sheet.getRange( startRow + i, 4).setValue("EMAIL_SENT"); }

我希望从第2行出现“EMAIL_SENT”。 但是,相反,它出现在第20行。 当我使用Logger写出startRow时,它显示为2.0,而不是2.我猜测2.0被认为是20,因为我住在芬兰,其中逗号而不是点用作小数点。 话虽如此,我的语言设置是用日语设置的,其中dot用作小数点。 所以,这种解释不符合逻辑,但这是我能想到的唯一解释。 我用的时候

Math.round( startRow )

这也无济于事。 有人可以建议解决方案吗? 谢谢!

I'm trying to run a script on a Google spreadsheet. The below is the code snippet:

var startRow = 2; var data = dataRange.getValues(); for (i in data) { sheet.getRange( startRow + i, 4).setValue("EMAIL_SENT"); }

I expect that "EMAIL_SENT" appears from the 2nd row. But, instead, it appears from the 20th row. When I write out startRow using Logger, it appears as 2.0, instead of 2. I am guessing that 2.0 is recognized as 20 since I live in Finland, where the comma, rather than dot, is used as a radix point. Having said that, my language setting is set with Japanese where dot is used for a radix point. So, this interpretation isn't logical, but this is the only explanation I could think of. When I used

Math.round( startRow )

This didn't help, either. Could anybody suggest solution? Thank you!

最满意答案

我不知道为什么,但由于某种原因,这种类型的循环不会创建编号索引( i )。 所以,你的脚本读取startRow + i就像说2和i ,而不是2加i 。

你没有看到数字20你看到数字2与索引0。

要更改此设置,您可以使用此类型的循环。

for(var i=0;i<data.length;i++){ sheet.getRange( startRow + i, 4).setValue("EMAIL_SENT"); }

或者你可以添加Number()到i

sheet.getRange( startRow + Number(i), 4).setValue("EMAIL_SENT");

I don't know why, but for some reason that type of loop does not create numbered index(i). So, your script reads startRow + i is like saying 2 and i, not 2 plus i.

Your not seeing the number 20 you are seeing the number 2 with the index 0.

To change this, you can either use this type of loop.

for(var i=0;i<data.length;i++){ sheet.getRange( startRow + i, 4).setValue("EMAIL_SENT"); }

Or you can just add Number() to the i

sheet.getRange( startRow + Number(i), 4).setValue("EMAIL_SENT");

更多推荐

本文发布于:2023-08-07 02:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1459399.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   Apps   Google   apps   script

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!