本文介绍了显示Google电子表格中有多少重复的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个练习要做:

删除列表DOUBLOONS



创建一个Object类型的变量:
var myObject = {}

var myObject = new Object()



使用Service SpreadsheetApp,水果。

紧固2维数组并返回,为每个新水果在对象中创建一个新条目。



如果一个水果已经列出,增加1,这个水果的计数器值。

myObject的结构示例:
myObject = {
Apple:1,
Pear:4
... dropoff Window
}放弃窗口



完成所有的水果,扣到myObject构建一个数据范围与2列(水果,在列表中出现的次数),并显示在列D和E的结果。



指示:
使用测试:if(myFruit in myObject){}来测试结果是否已经列出。



thi s是电子表格:



结果必须如下所示:





这个我的密码我被封锁了,我现在不该做什么,请帮助我

  // VARIABLE GLOBALE:DECLARATION DES FEUILLES 

var ui = SpreadsheetApp.getUi();
var mySpread = SpreadsheetApp.getActiveSpreadsheet();

// AJOUTE UN MENUPERSONNALIÉDANS LA SPREADSHEET
function onOpen(e){
ui.createMenu('Third-Step')
.addItem('Del重复','deldup')
.addToUi();

// SUPPRIMER LES DOUBLONS D'UNE LISTE

函数deldup(){
var sheet = SpreadsheetApp.getActiveSheet();
var result = [];如果(sheet!= null){
var myFruit = sheet.getRange(1,1,sheet.getLastRow(),3).getValues();


sheet.getRange(1,4,sheet.getLastRow() - 1,2).clearContent()
var i = 0;
var myObject = {
Pomme:[i],
Poire:[i],
Banane:[i],
Pêche :[i],
Carotte:[i]

};
for(var i = 0; i< myObject.length; i ++){



if(myFruit in myObject){

i + = 1;
}
result.push(myObject);
}
sheet.getRange(1,4,result.length,result [0] .length).setValues(result);
}

else {
sheet.toast(The Sheet is empty !!)
}


}


解决方案

您可以尝试使用此代码:

 函数deldup(){
var sheet = SpreadsheetApp.getActiveSheet();
var i = 0;
var results = [[Pomme,i],[Poire,i],[Pêche,i]];
if(sheet!= null){

var myFruit = sheet.getRange(1,1,sheet.getLastRow(),3).getValues();
sheet.getRange(1,4,sheet.getLastRow() - 1,2).clearContent();
var flag = 0; (var i = 0; i< myFruit.length; i ++){
for(var j = 0; j< myFruit [i] .length; j ++){$ b(

) (b)if(results.length!= 0){
for(var k = 0; k if(myFruit [i] [j] == results [k] [0]){
results [k] [1] ++;
flag = 1;
休息;
}
if(flag == 0){
results.push([myFruit [i] [j],1]);
}
}
}
else
results.push([myFruit [i] [j],1]);
}
}
sheet.getRange(1,4,results.length,2).setValues(results);
}
else {
sheet.toast(The Sheet is empty !!)
}
}

希望有帮助!


i have an exercise to do :

DELETE A LIST DOUBLOONS

Create a variable of type Object:var myObject = {}orvar myObject = new Object ()

Using the Service SpreadsheetApp, get the list of fruits.

Fasten the 2 dimensional array and returned, create a new entry in your object for each new fruit.

If a fruit has already been listed, increment of 1, the counter value to this fruit.

Examples of structures for myObject:myObject = {"Apple": 1,"Pear: 4...dropoff Window            }dropoff window

After completing all the fruit, buckle to myObject to build a data range with 2 columns (fruit, number of occurrences in the list) and display the result in columns D and E.

indication:use the test: if (myFruit in myObject) {} to test if the result has already been listed or not.

this is the spreadsheet :

http://i.stack.imgur.com/DV4E1.png

the result have to be like this :

http://i.stack.imgur.com/rqDFG.png

and this my code i'm blocked i don't what to do now please help me

//VARIABLE GLOBALE : DECLARATION DES FEUILLES

var ui = SpreadsheetApp.getUi();
var mySpread = SpreadsheetApp.getActiveSpreadsheet();

    // AJOUTE UN MENU PERSONNALIÉ DANS LA SPREADSHEET
    function onOpen(e) {
      ui.createMenu('Third-Step')
      .addItem('Del duplicates', 'deldup')
      .addToUi();
    }
    //SUPPRIMER LES DOUBLONS D’UNE LISTE

    function deldup() {
      var sheet =   SpreadsheetApp.getActiveSheet();
      var result = [];

      if (sheet != null){
      var myFruit =    sheet.getRange(1, 1, sheet.getLastRow(), 3).getValues();
                       sheet.getRange(1, 4, sheet.getLastRow() - 1, 2).clearContent()
      var i =0;
      var myObject =  {
                   "Pomme":[i],
                   "Poire":[i],
                   "Banane":[i],
                   "Pêche":[i],
                   "Carotte":[i]

                                 };                   
               for (var i=0; i< myObject.length; i++){



                 if(myFruit in myObject){

                  i += 1;
                 }
              result.push(myObject);
              } 
        sheet.getRange(1, 4, result.length, result[0].length).setValues(result);
      }

         else {
        sheet.toast("The Sheet is empty !!")
         }


    }
解决方案

You can try using this code(tested and working):

function deldup(){
  var sheet = SpreadsheetApp.getActiveSheet();
  var i=0;
  var results =[["Pomme", i], ["Poire", i], ["Pêche", i]   ];
  if (sheet != null){

  var myFruit = sheet.getRange(1, 1, sheet.getLastRow(), 3).getValues();
  sheet.getRange(1, 4, sheet.getLastRow() - 1, 2).clearContent();
  var flag = 0;

    for (var i=0; i< myFruit.length; i++){
        for(var j=0; j < myFruit[i].length; j++){
            if(results.length != 0){
                for(var k=0; k < 10; k++){
                   if(myFruit[i][j] == results[k][0]){
                        results[k][1]++;
                        flag = 1;
                        break;
                    }
                  if(flag == 0 ){
                    results.push([myFruit[i][j], 1]);
                  }
               }
           }
           else
           results.push([myFruit[i][j], 1]);
        }
     }
  sheet.getRange(1, 4, results.length, 2).setValues(results);
   }
  else {
    sheet.toast("The Sheet is empty !!")
  }
}

Hope that helps!

这篇关于显示Google电子表格中有多少重复的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 20:00