Home > Net >  Script AppendRow at the top
Script AppendRow at the top

Time:09-22

I have this little code to insert data from a form to a specific sheet.

function grabarEnSheets(e) {
  //Conectarse con sheets
  const libro=SpreadsheetApp.openById("SheetID")
  const hoja=libro.getSheetByName("Patrol-Logs")
  
  //Traer respuestas
  const respuestaEnviada=e.response;
  const respuestas=respuestaEnviada.getItemResponses();
  const Nombre = respuestas[0].getResponse();
  const Dia = respuestas[1].getResponse();
  const Tiempo = respuestas[2].getResponse();
  const Evidencia = respuestas[3].getResponse();
  const Traje = respuestas[4].getResponse();

  //Campos nuevos
  var fecha=new Date();

//Guardar respuestas en sheets
hoja.appendRow([fecha,Nombre,Tiempo,Dia,Evidencia,Traje])
}

function darPermisos(){
  SpreadsheetApp.openById("sheetID")
  FormApp.getActiveForm();
}

And the appendRow adds the data at the bottom of the sheet. So what I need is to append all entry data from the form and skip the first and second table. enter image description here

CodePudding user response:

From your following replying in the comment,

I don't know how to make appendRow to start adding the data at the third file, and not at the bottom.

I thought that you might have wanted to append a data row to the 3rd tab on the Google Spreadsheet. If my understanding is correct, how about the following modification?

From:

hoja.appendRow([fecha,Nombre,Tiempo,Dia,Evidencia,Traje])

To:

libro.getSheets()[2].appendRow([fecha,Nombre,Tiempo,Dia,Evidencia,Traje]);
  • libro.getSheets()[2] means the 3rd tab on the active Spreadsheet.

  • If you want to use appendRow to the specific sheet, you can also use the following script using the sheet name.

      libro.getSheetByName("###SheetName###").appendRow([fecha,Nombre,Tiempo,Dia,Evidencia,Traje]);
    

Reference:

  • Related