Google脚本/javascript |为什么getRange返回2D数组 [英] Google script/javascript | why does getRange return 2D array

查看:51
本文介绍了Google脚本/javascript |为什么getRange返回2D数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图从Google脚本的getRange中获取值,但我注意到它正在返回2D数组.我只是想知道为什么它返回2D数组而不是仅返回1D数组.

So I was trying to get values from getRange in google script but I noticed it was returning a 2D array. I was just wondering why it is returning a 2D array instead of just 1D array.

推荐答案

电子表格范围可以是单个单元格,也可以是行和列的范围,对于单个单元格,您可以使用 getValue()方法,该方法返回单个对象(字符串或数字或无论是在该小区),但是当多个小区被选择,我们必须能够知道在哪个行和列是每个元素,因此行值的阵列的选择,每行值集本身就是一个值数组.

A spreadsheet range can be a single cell or a range of rows and columns, for single cells you can use the getValue() method which returns a single object (string or number or whatever is in that cell) but when multiple cells are selected we have to be able to know in which row and column is each element, therefore the choice of an array of row values, each set of row values itself being an array of values.

您会注意到,在后一种情况下,使用的方法是 getValues()(带有S).

You'll notice that in this latter case the method to use is getValues() (with an S).

getValues()方法返回一个数组数组,以跟踪用于多个单元格选择的图纸行-列结构.

The getValues() method returns an array of arrays to keep track of the sheet row-Column structure for multiple cells selection.

如果您尝试对单个单元格或单个行(或单个列)使用 getValues(),则结果仍将是2维数组,但其长度和/或宽度将会是1.如果返回值的性质根据选择而有所不同,那将是非常令人不安的,您认为吗?

If ever you try to use getValues() for a single cell or a single row (or a single column), the result will still be a 2 dimension array but its length and/or width will be 1. It would have been very disturbing if the nature of the returned value had been different depending on the selection, don't you think ?

这篇关于Google脚本/javascript |为什么getRange返回2D数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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