SpreadsheetApp:getRange和setValues [英] SpreadsheetApp: getRange and setValues

查看:67
本文介绍了SpreadsheetApp:getRange和setValues的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Google SpreadsheetApp将2D数组写入工作表.尝试

  sheet.getRange(sheet.getLastRow()+ 1,1,array2d.length,array2d [0] .length).setValues(array2d); 

导致以下错误:

 数据中的行数与范围中的行数不匹配.数据有4个,但范围中有3个." 

如何从这一行代码中得到这样的错误?我使用数组的尺寸来指定电子表格中的范围,那么它们怎么可能不匹配?

(该行是

为了继续对您的问题进行故障排除,您可能会发现以下相关的超链接:

I would like to use Google SpreadsheetApp to write a 2D array into a sheet. Trying

sheet.getRange(sheet.getLastRow() + 1, 1, array2d.length, array2d[0].length).setValues(array2d);

leads to the following error:

"The number of rows in the data does not match the number of rows in the range. The data has 4 but the range has 3."

How is it possible to get an error like this from this line of code? I use the dimensions of the array to specify the range in the spreadsheet, so how can it be that they don't match?

(The line is part of https://github.com/alpatania/sassafras (function appendData_ in supporting_code).)

解决方案

When calling

sheet.getRange(sheet.getLastRow() + 1, 1, array2d.length, array2d[0].length).setValues(array2d);

You are just checking the length of the first row of your 2D-Array (using array2d[0].length). However, different rows may have different lengths as well. You can see below a short fragment of code that reproduces your issue:

In order to continue troubleshooting your issue you may find the following hyperlinks relevant:

这篇关于SpreadsheetApp:getRange和setValues的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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