1

I have a question for Google Script on how to split text with a separator at the same time i append a row with data.

Where 'content' has body text with the separator.

Here is my script:

function readMail() {
    var thread = GmailApp.getInboxThreads(0, 1)[0];
    var messages = thread.getMessages()[0];
    var content = messages.getPlainBody(); 
    var spread = SpreadsheetApp.openById('...');
    var sheet = spread.getSheetByName('...');
    sheet.appendRow([messages.getDate(), messages.getFrom(), content]);
}
Ivar
  • 6,138
  • 12
  • 49
  • 61
T O
  • 11
  • 2
  • 1
    Possible duplicate of [How do I split a string, breaking at a particular character?](https://stackoverflow.com/questions/96428/how-do-i-split-a-string-breaking-at-a-particular-character) – Syed Waqas Bukhary Jan 21 '18 at 12:54

1 Answers1

0

One possible answer to this is to inject the formula for splitting at the same time you append the row.

 var lastRow = sheet.getLastRow();
 var split = '=SPLIT(C' + lastRow + ',",")'
 sheet.appendRow(['','','split, me', split]);
Jason Allshorn
  • 1,625
  • 1
  • 18
  • 27
  • Thanks Jason, I had to put change var lastRow = sheet.getLastRow()+1; to get the same row as the appendRow to let the formula work, but it works just fine now. – T O Jan 23 '18 at 09:39