排序函数错误6列

时间:2014-05-25 11:49:11

标签: google-sheets

我有一个功能,可以将信息从一个工作表复制并粘贴到另外两个工作表,然后对所有三个工作表进行不同的排序。第一个工作表是第1列的简单alpha排序,第二个工作表是第2列的alpha排序,第三个工作表按顺序按列3-8排序。在“学生列表详细信息”上编辑数据时,用户单击“排序”按钮以​​运行此脚本并修改所有三个页面。但是,第三页(AutoDocHeidiOnly2)未正确排序。没有给出错误,它似乎运行正常,但工作表没有排序。

function myFunction() {

  //var copyFromRange = 'Student List Details!A3:H1000';

  //var copyToRangeStart = 'AutoDocHeidiOnly!A3:H1000';
   // copyValuesOnly(copyFromRange, copyToRangeStart);

  var sld = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Student List Details");
  var ado = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("AutoDocHeidiOnly");
  var ado2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("AutoDocHeidiOnly2");
  var sourceRange=sld.getRange("A3:H1000");
  var sourceData = sourceRange.getValues();
  ado.getRange(3,1,sourceData.length,sourceData[0].length).setValues(sourceData);
  ado2.getRange(3,1,sourceData.length,sourceData[0].length).setValues(sourceData);
  var lastRow = sld.getLastRow()
   var range = sld.getRange(3,1,lastRow,9);
  range.sort(1);
  var lastRow = ado.getLastRow()
   var range = ado.getRange(3,1,lastRow,8);
  range.sort(2);
   var lastRow = ado2.getLastRow()
   var range = ado2.getRange(3,1,lastRow,8);
  range.sort({Column: 3},{Column: 4},{Column: 5},{Column: 6},{Column: 7},{Column: 8});
 // ado.getDataRange()

   // var rowssld = sld.getDataRange().getValues();
//  var ado2 = sheet.getSheets('AutoDocHeidiOnly2')

  //var row = sld.getRange(88, 3, 1, 9).getValues();



 // ado.appendRow(row[0]);

// var targetrange = ado.getRange(3, 1, sld.getLastRow(), 9);
  //var rangeValues = sld.getRange(3, 1, sld.getLastRow(), 9).getValues();
 //targetrange.setValues(rangeValues);
//for (var i = 3; i < rowssld.length; i++){
// for (var j = 1; j < 9; j++){
 //  var val=sld.getRange(i,j).getValue();
 //  ado.getRange(i,j).setValue(val);
 // }
 // }

  Browser.msgBox("FINISHED") ;  
}


function test()
{
   var sld = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Student List Details");
  var ado = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("AutoDocHeidiOnly");
  var ado2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("AutoDocHeidiOnly2");
  var sourceRange=sld.getRange("A3:H1000");
  var sourceData = sourceRange.getValues();
  ado.getRange(3,1,sourceData.length,sourceData[0].length).setValues(sourceData);
  ado2.getRange(3,1,sourceData.length,sourceData[0].length).setValues(sourceData);
  var lastRow = sld.getLastRow()
   var range = sld.getRange(3,1,lastRow,9);
  range.sort(1);
  var lastRow = ado.getLastRow()
   var range = ado.getRange(3,1,lastRow,8);
  range.sort(2);
   var lastRow = ado2.getLastRow()
   var range = ado2.getRange(3,1,lastRow,8);
  range.sort(3);
 // ado.getDataRange()

   // var rowssld = sld.getDataRange().getValues();
//  var ado2 = sheet.getSheets('AutoDocHeidiOnly2')

  //var row = sld.getRange(88, 3, 1, 9).getValues();



 // ado.appendRow(row[0]);

// var targetrange = ado.getRange(3, 1, sld.getLastRow(), 9);
  //var rangeValues = sld.getRange(3, 1, sld.getLastRow(), 9).getValues();
 //targetrange.setValues(rangeValues);
//for (var i = 3; i < rowssld.length; i++){
// for (var j = 1; j < 9; j++){
 //  var val=sld.getRange(i,j).getValue();
 //  ado.getRange(i,j).setValue(val);
 // }
 // }

  Browser.msgBox("FINISHED") ;  


}

//function copyValuesOnly(copyFromRange, copyToRangeStart) {

//  var ss = SpreadsheetApp.getActiveSpreadsheet();

  //var source = ss.getRange(copyFromRange);

  //source.copyTo(ss.getRange(copyToRangeStart), {contentsOnly: true});

1 个答案:

答案 0 :(得分:0)

刚刚对此进行了修改,但您是否尝试在第3张纸上指定列的升序?例如:

 range.sort({Column: 3},{Column: 4},{Column: 5},{Column: 6},{Column: 7},{Column: 8});

尝试:

 range.sort([{Column: 3, ascending: true},{Column: 4, ascending: true},{Column: 5, ascending: true},{Column: 6, ascending: true},{Column: 7, ascending: true},{Column: 8, ascending: true}]);

我绝不是这里的向导之一,但我自己遇到了一些时髦的问题,所以只是想要有所帮助! :)