Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

113
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda