为什么附加行不能与数组一起使用?

编程入门 行业动态 更新时间:2024-10-20 06:30:32
本文介绍了为什么附加行不能与数组一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试在工作表底部插入一行,但我看到的不是我的值,而是类似于您尝试在 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-17 20:02:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/921548.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   能与

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!