问题描述
我正在尝试在工作表的底部插入一行,但是我看到的文本与您尝试用Java打印数组时发生的情况类似,而不是我的值。我检查了数组是否用logger正确制作,并且具有我想要的值。
I am trying to insert a row to the bottom of a sheet, but instead of my values I see text similar to what happens when you try to print an array in Java. I checked to see if the array is made correctly with logger and it has the values I want.
var name = e.range.getRow() + SpreadsheetApp.getActiveSpreadsheet().getName();
var array = e.range.getValues().concat(name);
Logger.log(array.toString());
masterSheet.appendRow(array);
array
包含时间戳记,string1,string2 ,最后是我串联的名称。相反,我得到类似 [Ljava.lang.Object; @ 7dch7145
array
contains a timestamp, string1, string2, and finally the name I concatenated. Instead I get something like [Ljava.lang.Object;@7dch7145
推荐答案
使用 getValues()
似乎有问题,它返回一个二维数组,需要这样访问。
It looks like a problem with your use of getValues()
which returns a two-dimensional array and needs to be accessed as such.
对象[] [] —二维值数组
Object[][] — a two-dimensional array of values
我相信此修改将设置您的 var数组
应该可以解决问题,假设您的数据范围是一行(索引0将是第一行,否则只需将索引更改为所需的行即可):
I believe this edit to setting your var array
should do the trick, assuming your data range is for a single row (index 0 will be the first row, otherwise just change the index to the row you want):
var array = e.range.getValues()[0].concat(name);
这篇关于为什么不将行附加到数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!