为什么附加行不能与数组一起使用? [英] Why won't append row work with array?

查看:34
本文介绍了为什么附加行不能与数组一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在工作表底部插入一行,但我看到的不是我的值,而是类似于您尝试在 Java 中打印数组时发生的情况的文本.我检查了数组是否使用记录器正确创建并且它具有我想要的值.

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.

GAS API 参考:getValues()

返回

Object[][] — 二维值数组

Object[][] — a two-dimensional array of values

我相信这个设置你的 var array 的编辑应该可以解决问题,假设你的数据范围是单行(索引 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);

这篇关于为什么附加行不能与数组一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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