无法将数组转换为object [] []

时间:2017-11-15 00:38:12

标签: javascript arrays google-apps-script

我目前正在使用两个数组(它们的大小不同,没有相同的顺序或格式),我的目标是从一个数组获取信息并输入另一个数组,最终使用setRange()方法输入从一个电子表格到另一个电子表格的数据。到目前为止,我有以下代码:

fileName = currentFile.getName()
fileSheet = SpreadsheetApp.open(currentFile).getSheetByName(fileName);
var SAFRange = fileSheet.getRange("A1:K29").getValues(); // values from the SAF
var SKU = 0 //used as a counter to see how many SKUs are in a SAF.
for (i = 15; i <= 27; i++) { // first loop just checks how many information is needed
    if (!(SAFRange[i][0] == "")) {
        SKU++; // increase counter, used to determined how many rows are 
        //needed
    } else {
        break;
    }
}
//recap is the destination spreadsheet defined before
//recLRow is the last row of recap
//The array below is an array with al blank values  
var newInfo = recap.getRange("A" + (recLRow + 1).toString() + ":R" + (recLRow + SKU+1).toString()).getValues(); // gets  the values of the range that the information will be posted. in this case all "" -- Blanks
Logger.log(newInfo)
var rowIndex = 0 //row index for the second array
for (i = 15; i <= (15 + SKU); i++) { // This Loop gets the information from the SAF and puts in the appropiate Range
    newInfo.splice([rowIndex][4], 1, SAFRange[i][0]); //TBH im not sure how
    Logger.log(newInfo);                              //Splice works, 
    rowIndex++;                                       //Error might me here
}
//Below is  where the program flags an error.
recap.getRange("A" + (recLRow + 1).toString() + ":R" + (recLRow + SKU+1).toString()).setValues(newInfo);

我在拼接之前和之后都有这个日志:

Before: [[, , , , , , , , , , , , , , , , , ], [, , , , , , , , , , , , , , , , , ]]
After: [00029HB00, [, , , , , , , , , , , , , , , , , ]]

所以我知道我做错了。我想在第一个数组中插入信息,而不是替换整个事物

  

错误:无法将数组转换为object [] []

0 个答案:

没有答案
相关问题