简体   繁体   English

将GoogleSheet复制到另一个工作表时的数组大小问题

[英]Array size issue when copying GoogleSheet to another sheet

I need to get a sheet of data as an array, perform some processing, then save it to another sheet. 我需要获取一张数据作为数组,执行一些处理,然后将其保存到另一张纸上。

Without attempting any intermediate processing, 无需尝试任何中间处理,

var booking = getRowsData(sheet);  //should create the array

var range = target.getRange(lastDBRow+1,1,numRows); //obtains the destination range (numRows logged as 3)

then 然后

range.setValues([booking]); //tries to save the values but throws an error "Incorrect range height, was 1 but should be 3"

Checking the booking object with 检查预订对象

var response = ui.prompt(booking.length + "  " + booking[0].length, ui.ButtonSet.OK);

shows length 3 and booking[0].length (which I understood to be the columns) as undefined.... 显示长度3和booking [0] .length(我理解为列)为未定义...。

So why the row length mismatch? 那么为什么行长不匹配? And should the columns value be undefined? 列值是否应该不确定?

My thanks in advance! 预先感谢!

The full code is : 完整的代码是:

var ss = SpreadsheetApp.getActive(); 
var sheet = ss.getSheetByName('New booking');
var headers = sheet.getRange(1, 1,1,sheet.getLastColumn());
var lastRow = sheet.getLastRow();
var numRows= lastRow-1

var target = ss.getSheetByName('Test');  //temp redirect to test sheet
var lastDBRow =target.getLastRow();      //we want to append the data after this


var booking = getRowsData(sheet);        // Get data to copy as array object
= ui.prompt(booking.length + "  " + booking[0].length, ui.ButtonSet.OK);
//                                       Returns 3  Undefined

var response = ui.prompt(numRows, ui.ButtonSet.OK);
//                                         Returns 3

var range = target.getRange(lastDBRow+1,1,numRows);   //  Must match range size
range.setValues([booking]);
}

Looks to me like there is no column count defined in this range: var range = target.getRange(lastDBRow+1,1,numRows); 在我看来,此范围内未定义任何列数:var range = target.getRange(lastDBRow + 1,1,numRows); // Must match range size range.setValues([booking]); //必须匹配范围大小range.setValues([booking]); Without being about to use debug, I can't confirm my idea, but I see you are defining the starting row, the starting column and the number of rows, but not the number of columns. 在不打算使用调试的情况下,我无法确认我的想法,但是我看到您正在定义起始行,起始列和行数,但未定义列数。 I don't know for sure if that error message would be caused by that, but it looks like something to consider. 我不确定该错误消息是否是由该原因引起的,但似乎需要考虑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM