merge values in column in a row with the quotes separator “|”, based on a comparison with the values of another column

前端 未结 2 668
有刺的猬
有刺的猬 2021-01-16 12:21

as the title suggests I\'m trying to find a way to treat some data in a spreadsheet to google app. I think the best way is to directly set an example and thank you in advan

2条回答
  •  Happy的楠姐
    2021-01-16 12:44

    have a look at this post, he want to do almost the same. Modifying 2 lines of the code and it's done:

    function myFunction() {
      var objList={};
      var ss = SpreadsheetApp.getActive().getActiveSheet();
      var data = ss.getDataRange().getValues();
      for(var i in data){
        // for(var j in data[i]){
          if(typeof objList[data[i][0]]=="undefined"){
            objList[data[i][0]]=[]; // new array
            objList[data[i][0]].push(data[i][1]); // push the value of the second column
          }
          else{
            objList[data[i][0]].push(data[i][1]);
          }
        //}
      }
      var objTable=[];
      for(var k in objList){
       objTable.push([k,objList[k]]);
      }
      Logger.log(objTable);
      ss.clear();
      ss.getRange(1, 1, objTable.length, objTable[0].length).setValues(objTable);
    }
    

提交回复
热议问题