本文介绍了Google表格:如何appendRow与2d getValues数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找这个功能的帮助。

背景
我正在为我们公司创建基于Google表单的订单,没有太大的支持大约100商店。问题出在操作上,如果你愿意的话,可以在数据收集表中添加一行。

 函数grabOrder(){
var ordNum = ss.getRange ( B2)的getValue();
var storeCode = ss.getRange(B1)。getValue();
var ordValues = ss.getRange(A1:A100)。getValues();

insertInfo(ordNum,storeCode,ordValues);


函数insertInfo(ordNum,storeCode,ordValues){

ssDb.appendRow([ordNum,storeCode,ordValues]);




$ b

结果:运行我的代码它不会抛出错误,它会完成操作并且ordNum,storeCode正常显示。然而,ordValues出现在这里:

[Ljava.lang.Object; @ 78f4b2bd



注意:我提供的代码是一个极其简化的代码版本,因为我唯一的问题在于appendRow数组。



潜在解决方案

strong>:我意识到getValues会抓取一个二维数组,而appenRow只会采用一维。我的猜测是我需要将2d数组转换为1d数组并将其存储在变量中?请帮助!



已解决:以下是我所做的:

  var orderString = timeStamp +,+ ordNum +,+ clc +,+ orderRng.toString(); 
var orderValues = orderString.split(,);

然后,我简单地传递了新的数组,如下所示:

  ssDb.appendRow(orderValues); 

希望你们能在将来找到它。

解决方案
  function grabOrder(){
var ordNum = ss.getRange(B2)。getValue();
var storeCode = ss.getRange(B1)。getValue();

var ordValues = ss.getRange(A1:A100)
.getValues()
.map(函数(行){
return row [0] ;
});

insertInfo(ordNum,storeCode,ordValues);


函数insertInfo(ordNum,storeCode,ordValues){
ssDb.appendRow([ordNum,storeCode] .concat(ordValues));
}


Looking for help on this function.

Background:I am creating a Google Sheets based order form for our company, nothing too large its going to support about 100 stores. The problem lies with the operation to append a row to my data collection sheet, database if you will. I'm having trouble with the .appendRow operation.

function grabOrder(){
    var ordNum = ss.getRange("B2").getValue();
    var storeCode = ss.getRange("B1").getValue();
    var ordValues = ss.getRange("A1:A100").getValues();

    insertInfo(ordNum, storeCode, ordValues);
}

function insertInfo(ordNum, storeCode ,ordValues){

    ssDb.appendRow([ordNum, storeCode, ordValues]);

}

Result: When running my code it doesn't throw an error, it completes the operation and ordNum, storeCode show up properly. However ordValues appears with this:

[Ljava.lang.Object;@78f4b2bd

Note: The code I have provided is an extremely simplified version of my code, as my only issue lies with the appendRow array.

Potential Solution: I am aware that the getValues grabs a two-dimensional array, and the appenRow will only take one dimensional. My guess is I need to convert the 2d-array into a 1d array and have it stored in a variable? Help please!

SOLVED: Here is what I did:

var orderString = timeStamp + "," + ordNum + "," + clc + "," + orderRng.toString();
var orderValues = orderString.split(",");

I then simply passed the new array like so:

ssDb.appendRow(orderValues);

Hope you guys find use for this in the future.

解决方案
function grabOrder(){
  var ordNum = ss.getRange("B2").getValue();
  var storeCode = ss.getRange("B1").getValue();

  var ordValues = ss.getRange("A1:A100")
    .getValues()
    .map(function (row) {
      return row[0];
    });

  insertInfo(ordNum, storeCode, ordValues);
}

function insertInfo(ordNum, storeCode ,ordValues){
  ssDb.appendRow([ordNum, storeCode].concat(ordValues));
}

这篇关于Google表格:如何appendRow与2d getValues数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 12:19