Can't Figure out why setValue() returns an err

2019-08-10 14:15发布

Code I've run 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);

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.

What could be going on?

2条回答
Evening l夕情丶
2楼-- · 2019-08-10 15:00

While the other answer is correct, it doesn't explain the reason why you are having this error.

As mentioned in the documentation about setValues(), the argument for setValues() must be a 2 dimensions array (an array of arrays) either built from scratch or captured using getValues().

see The doc below : enter image description here

By the way, the funny thing is that the title of your post uses setValue() without S while your code has the problematic S ...

查看更多
对你真心纯属浪费
3楼-- · 2019-08-10 15:01

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

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

查看更多
登录 后发表回答