简体   繁体   中英

Google Spreadsheet Filter Column

I have a Spreadsheet within Google Drive that has 5 more spreadsheets feeding information from a copy of the main spreadsheet[0] of the document. I have made filters on each of the other spreadsheets [1],[2],[3],[4] in column G with the range ('G1:G1000') I have a script but is not picking the specific columns in those extra spreadsheets

Thanks for the help!

   function onOpen(){

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var filterMenuEntries = [{name: "filter Column1", functionName: "filter"}];
  ss.addMenu("choose filter", filterMenuEntries);

  }

 function filter(){
//spreadsheet identifier
 var key = '1X7qA--8UxVj37SHON14F4KdrF3DDPpKMtUmhgHVmt51GW4c';
  var ss = SpreadsheetApp.openById(key);
 var rows = sheet.getDataRange('G1:G1000');// should I set a range here?
 var numRows = rows.getNumRows();
 var values = rows.getValues();

  ss.getActiveSheet();


 for (var i=1; i <=numRows -1; i++){

   var row =values[i];

   // Column value
   var myValue = row[8] //not sure if this is column 'G' or not

   // filter value 
   if (myValue == "DEVPS"){

     sheet.hideRows(i+1);

     }

  }

You should change this line:

var ss = SpreadsheetApp.openById(key);

To

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet1 = ss.getSheets()[1];

and work with sheet1 (and others) as you wish.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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