Skip to content

Instantly share code, notes, and snippets.

@bram-atmire
Created February 22, 2014 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bram-atmire/9158007 to your computer and use it in GitHub Desktop.
Save bram-atmire/9158007 to your computer and use it in GitHub Desktop.
SimpleBaget
function calculateBartBagetBill() {
var ss, sheet, cell, regExp, threads, j, mails, i, mail, body, match, broodje, date;
ss = SpreadsheetApp.getActiveSpreadsheet();
sheet = ss.getSheets()[0];
cell = sheet.getRange("A1");
threads = GmailApp.search('subject:Bram to:bartbaget@skynet.be after:2013/11/01 before:2014/03/01');
for (j = 0; j < threads.length; j++) {
mails = threads[j].getMessages();
for (i = 0; i < mails.length; i++) {
mail = mails[i];
subject = mail.getSubject();
salade = subject.substring(subject.indexOf('-') + 2, subject.indexOf('- B') - 1);
date = mail.getDate();
cell.offset(j,0).setValue(date);
cell.offset(j,1).setValue(salade);
cell.offset(j,2).setNumberFormat('0.00€').setValue(4.95);
}
}
cell.offset(threads.length, 1)
.setFontWeight('bold')
.setValue('Totaal:');
cell.offset(threads.length, 2)
.setFontWeight('bold')
.setNumberFormat('0.00€')
.setFormula("=SUM(C1:C" + threads.length +")");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment