Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!