我有一个用于"leaderboard"类型页面的Google脚本,其中vlookup公式等为每个用户在单个选项卡上提供总体得分 . 我检查具有用户名的列(B),找到填充的最后一行,创建一个从B列到AC列中选择的范围,然后按降序排序,然后输入用户名 . 我找到了填充最后一行here的方法,并了解了我必须在其他地方前进一行的事实,我现在无法再找到它 .

但是,它不包括排序中的底层用户 . 我已尝试对所选范围执行其他操作,并且它确实包括最后一行(例如,setBackground显示在适当范围内的颜色下方) . 我觉得它与1有关,以及它如何处理整数与字符串,但我找不到合适的组合 .

注意:工作表上没有冷冻窗格 . 我查了一下 .

var avalsnew = xpdoc.getRange('b2:b').getValues(); 
  //I've tried both b1 and b2 here

  var alastnew = avalsnew.filter(String).length;
  alastnew = parseInt(alastnew) + 1; 
  //Tried with and without this line, which is why I suspect this is part of the problem

  var percentsort = percentdoc.getRange('b2:ac' + alastnew);
  percentsort.setBackground('green'); 
  //this includes the last row
  percentsort.sort([{column: 29, ascending: false}, {column: 2, ascending: true}]); 
  //but this does not