J'ai un script (combiné) qui exécute trois fonctions. Tout d'abord, il divise les réponses de formulaire en lignes (split), puis il est censé trier les réponses par ordre alphabétique (tri), et enfin supprimer toutes les lignes qui contiennent une cellule vide dans une colonne spécifique. Je suis assez nouveau pour utiliser des scripts, mais je pensais que cela fonctionnait. Maintenant, quand j'essaie de l'exécuter ou de déboguer, il donne "ReferenceError:" sort "n'est pas défini." (Ligne 3, fichier "Combined") Je suis sûr qu'il y a une explication assez simple. exécuter sur le formulaire soumettre, le changement, et ouvert.La fonction Google Script ReferenceError n'est pas définie
Quiconque est prêt à examiner et à offrir une suggestion? Le reste semble fonctionner.
function combined() {
SPLIT();
sort();
deleteRows();
function SPLIT() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh0 = ss.getSheets()[0], sh1 = ss.getSheets()[1];
// get data from sheet 2
var data = sh1.getDataRange().getValues();
// create array to hold data
var aMain = new Array();
// itterate through data and add to array
// j=3 is the column it starts to loop with, j<9 tells it where to stop.
// in the aMain.push line, use data[i][j] for the rows to search and put in the one column.
// in the last line, change the last number to equal the number of columns in your final sheet.
// the first number in getrange is the row the data starts on... not sure about the 1.
for(var i=1, dLen=data.length; i<dLen; i++) {
for(var j=5; j<9; j++) {
aMain.push([data[i][0],data[i][1],data[i][2],data[i][3],data[i][4],data[i][j]]);
}
// add array of data to first sheet
sh0.getRange(2, 1, aMain.length, 6).setValues(aMain);
}
function sort() {
/** Variables for customization:
Each column to sort takes two variables:
1) the column index (i.e. column A has a colum index of 1
2) Sort Asecnding -- default is to sort ascending. Set to false to sort descending
**/
//Variable for column to sort first
var sortFirst = 3; //index of column to be sorted by; 1 = column A, 2 = column B, etc.
var sortFirstAsc = true; //Set to false to sort descending
//Variables for column to sort second
var sortSecond = 2;
var sortSecondAsc = true;
//Variables for column to sort third
var sortThird = 6;
var sortThirdAsc = true;//Number of header rows
var headerRows = 1;
/** End Variables for customization**/
/** Begin sorting function **/
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh0 = ss.getSheets()[0];
var range = sh0.getRange(headerRows+1, 1, sh0.getMaxRows()-headerRows, sh0.getLastColumn());
range.sort([{column: sortFirst, ascending: sortFirstAsc}, {column: sortSecond, ascending: sortSecondAsc}, {column: sortThird, ascending: sortThirdAsc},]);
function deleteRows() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
// get data from the first sheet - the first sheet start with 0, we can also name a specific sheet by name but that's a little different setup.
var sh0 = ss.getSheets()[0];
var rows = ss.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
var rowsDeleted = 0;
for (var i = 0; i <= numRows - 1; i++) {
var row = values[i];
if (row[5] == 'delete' || row[5] == '') { // This searches all cells in column (change to row[1] for columns B and so on) and deletes row if cell is empty or has value 'delete'.
sh0.deleteRow((parseInt(i)+1) - rowsDeleted);
rowsDeleted++;
}
}
}
}
}
}
avez-vous raté le crochet de fermeture sur le tri? – OblongMedulla