无法弄清楚为什么setValue()返回错误 [英] Can't Figure out why setValue() returns an error

查看:109
本文介绍了无法弄清楚为什么setValue()返回错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行v1的代码:

  var G = SpreadsheetApp.getActiveSheet();  
  var Resp1 = UrlFetchApp.fetch(url1, parameters);
  var parResp1 = JSON.parse(Resp1);               
  var k = parseInt(parResp1.time);
  G.getRange("B5").setValues(k);

代码v2更改将第4行替换为:

Code v2 Change replaces 4th line with:

var k = JSON.stringify(parResp1.time);

运行代码后,我收到此错误消息

After I run my Code I get this error message

Cannot find method setValues(number). (line 27, file "Code")

返回的值是一个数字,但我不明白为什么它不将其视为一个数字.

The Value that is returned is a number but I don't understand why it doesn't see it as one.

可能会发生什么?

推荐答案

如果您只想更新单个单元格,则在您的情况下,getRange("B5")应该使用setValue而不是setValues

If you only want to update a single cell, in your case getRange("B5") you should use setValue, not setValues

setValues将用于您要为两点之间的范围(例如"A1:B2")设置值的情况下

setValues would be used in the case where you want to set the values for a range between two points such as "A1:B2"

这篇关于无法弄清楚为什么setValue()返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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