有关范围大小的错误消息与测量值冲突

时间:2013-10-18 00:01:21

标签: google-apps-script google-sheets

我有一个脚本从例程中获取一个数组,然后想要将它写入电子表格表中的范围。当我尝试将数组写入范围时,我收到以下错误消息。

Incorrect range width, was 53 but should be 25 (line 120, file "ScrubRowsFromVolDBSpreadsheet")

编写脚本的脚本如下所示:

var cleanedRows=cleanData(source, source_sheet_name,cleanDataSheet);

  var numCleanedRows=cleanedRows.length;

  var numCleanedCols=cleanedRows[0].length;

  Logger.log("numCleanedRows = "+numCleanedRows);

  Logger.log("numCleanedCols = "+numCleanedCols);

  var tempRange=ssOut.getSheetByName("ScrubbedRows").getRange(2,1,numCleanedRows,numCleanedCols);

  Logger.log("tempRangeRows="+tempRange.getHeight());

  Logger.log("tempRangeCols="+tempRange.getWidth());

  //

  tempRange.setValues(cleanedRows);  //// LINE 120

执行期间生成的记录器条目如下所示:

[13-10-17 16:43:07:888 PDT] numCleanedRows = 100

[13-10-17 16:43:07:888 PDT] numCleanedCols = 25

[13-10-17 16:43:07:905 PDT] tempRangeRows=100

[13-10-17 16:43:07:906 PDT] tempRangeCols=25

导致这种脱节的原因是什么?如何将数组写入范围?

1 个答案:

答案 0 :(得分:0)

您只检查第一行的长度。也许cleaningRows有一些包含更多项目(列)的行?