我正在尝试对工作表中的一列信息进行排序,但是当我运行程序时,我不断收到错误。我在脚本中执行该函数两次。尝试有效,但第二次尝试无效。它说它超出了范围,但当我交叉检查时,参数似乎是正确的。我已附上以下部分内容作为参考:
//Section C: Filtering data by current month into third sheet.
var sheet3 = ss.getSheetByName('Summarized Data');
var beginDate_current = sheet3.getRange("B2").getValue();
var endDate_current = sheet3.getRange("B3").getValue();
//Section D: Setting filter criteria based on dates in Data Overview sheet.
var filteredData = rngData.filter(function(row)
{var date = row[0]; return date >= beginDate_current && date <= endDate_current});
//Section E: Setting filtered data into Current Month table in Summarized Data sheet.
sheet3.getRange("B7").getDataRegion().offset(6,0).clearContent();
sheet3.getRange(7,3,filteredData.length,filteredData[1].length).setValues(filteredData);
sheet3.getRange(7,3,filteredData.length,filteredData[0].length).sort([{column: 3, ascending: true}]);
//Section F: Filtering data by previous quarter into third sheet.
var beginDate_quarter = sheet3.getRange("B5").getValue();
var endDate_quarter = sheet3.getRange("B6").getValue();
//Section G: Setting filter criteria for quarterly months.
var filteredData = rngData.filter(function(row)
{var date = row[0]; return date >= beginDate_quarter && date <= endDate_quarter});
//Section H: Setting filtered data into Previous Quarter table in Summarized Data sheet.
sheet3.getRange("I7").getDataRegion().offset(6,0).clearContent();
sheet3.getRange(7,9,filteredData.length,filteredData[0].length).setValues(filteredData);
sheet3.getRange(7,9,filteredData.length,filteredData[0].length).sort([{column: 7, ascending: true}]);
(错误适用于代码中的最后一行)
试试这个:
var sheet3 = ss.getSheetByName('Summarized Data');
var beginDate_current = sheet3.getRange("B2").getValue();
var endDate_current = sheet3.getRange("B3").getValue();
var filteredData = rngData.filter(function(row)
{var date = row[0]; return date.valueOf() >= beginDate_current.valueOf() && date.valueOf() <= endDate_current.valueOf()});
sheet3.getRange("B7").getDataRegion().offset(6,0).clearContent();
sheet3.getRange(7,3,filteredData.length,filteredData[1].length).setValues(filteredData);
sheet3.getRange(7,3,filteredData.length,filteredData[0].length).sort([{column: 3, ascending: true}]);
var beginDate_quarter = sheet3.getRange("B5").getValue();
var endDate_quarter = sheet3.getRange("B6").getValue();
var filteredData = rngData.filter(function(row)
{var date = row[0]; return date.valueOf() >= beginDate_quarter.valueOf() && date.valueOf() <= endDate_quarter.valueOf()});
sheet3.getRange("I7").getDataRegion().offset(6,0).clearContent();
sheet3.getRange(7,9,filteredData.length,filteredData[0].length).setValues(filteredData);
sheet3.getRange(7,9,filteredData.length,filteredData[0].length).sort([{column: 7, ascending: true}]);