Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

114
Vistas
How to specify column position when importing Gmail contents into a spreadsheet?

When importing Gmail contents into a spreadsheet If there is a specific item that is repeated This is a Google app script where Lastrow is automatically added.

I want to specify the desired column position for each item.

Please help me.


function myFunction()
{
  var threads = GmailApp.search('label:extra is:unread');
  var messages = GmailApp.getMessagesForThreads(threads);
  var sheet = SpreadsheetApp.getActive().getSheetByName('2021');

  for(var i=0; i<messages.length; i++)
  {
    
    var plainBody = messages[i][0].getPlainBody();
    var lastRow = sheet.getLastRow();

    const regex=/ex0:(.*)\n(.*)ex1:(.*)\n(.*)ex2:(.*)\n/g;

    
    if(!plainBody.match(regex))
    {
      continue;
    }

    var data = plainBody.match(regex).map(x=>
    {
        var a0 = (/ex0:(.*)/).test(x)? RegExp.$1 : '0';
        var a1 = (/ex1:(.*)/).test(x)? RegExp.$1 : '0';
        var a2 = (/ex2:(.*)/).test(x)? RegExp.$1 : '0';

        return [a0, a1, a2];
    });

    
    sheet.getRange(lastRow+1,1,data.length,data[0].length).setValues(data);
    
  }

  threads.forEach(function(thread) {
  thread.markRead();
  Utilities.sleep(100);
  });

}

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As a guess. Suppose your desired columns are: B, D, F. Then try to change this line

sheet.getRange(lastRow+1,1,data.length,data[0].length).setValues(data);

with this:

sheet.getRange('B' + lastRow).setValue(data[0]);
sheet.getRange('D' + lastRow).setValue(data[1]);
sheet.getRange('F' + lastRow).setValue(data[2]);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda