I have created a table in Google Sheets and I want to send automatically that table (25 rows, 2 columns) every 5 days to a specific email.
I already know how to send email via script, basically you use MailApp.sendEmail.
function sendFuelcount() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
sheet.setActiveSheet(sheet.getSheets()[0]);
var column1 = sheet.getRange("D2:D25").getValue();
var column2 = sheet.getRange("A2:A25").getValue();
var data = Utilities.formatDate(new Date(), "GMT", "dd-MMM-yyyy")
var msg = ""+nome+" "+fuel+"\n"
MailApp.sendEmail("[email protected]", ""+data+"", msg, {
name: 'Auto Message'});
This is the code so far, but unfortunately, it only writes the first row of the two columns instead of the 25 x 2 values.
In email I get:
Column11 Column12
What I want in email body is:
Column11 Column12
Column21 Column22
Column31 Column32
Column41 Column42
Column51 Column52
Until Column 25,1 and Column 25,2 or copy of the Google Sheet table.
Hope I have made myself clear.
Thank you.
EDIT: The answer below does the trick for export all values but not in a organized way.
What I get in the email is this:
A,B,C,D,...,i
1,2,3,4,...,j
What I want is this:
A - 1
B - 2
C - 3
D - 4
i - j
Is there a way to do this? Meaning how to organize and show that in the email. Like a table.