function B2B() {
var summary = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Summary");
var subject = "B2B - Delivery Status on";
var recipient = "******@***.in";
var dataRange = summary.getRange('B2:AA49');
var data = dataRange.getValues();
summary.getRange(2, 2, 25, 25).getValue;
var body = "I just discovered Apps Script and it's so cool!" + data;
MailApp.sendEmail(recipient, subject, body);
}
Used this query which is working and mail is going but, selected data range is table which i am not getting in table format in the mail.
Try this
function B2B() {
var summary = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Summary");
var subject = "B2B - Delivery Status on";
var recipient = "******@***.in";
var dataRange = summary.getRange('B1:AA49');
var [headers, ...rows] = dataRange.getValues();
MailApp.sendEmail({
to: recipient,
subject: subject,
htmlBody: "I just discovered Apps Script and it's so cool!" + "<br><br>" + tableHTML([headers], rows)
})
}
function tableHTML(headers, data) {
var tableformat = 'cellspacing="2" cellpadding="2" border="1" style="width:100%;border-collapse:collapse;border:1px solid #ccc"';
var header = headers.map(h => '<tr><th>' + h.join('</th><th>') + '</th></tr>')
var rows = data.map(r => '<tr><td>' + r.join('</td><td>') + '</td></tr>')
return '<table ' + tableformat + ' >\n' + header.join('\n') + rows.join('\n') + '</table>'
}
you need htmlbody instead of body
tableHTML is a function that will tranform the data into a table
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.