简体   繁体   English

如何发送带有格式化 html 表格和消息的电子邮件?

[英]How to send an email with a formatted html table and message?

I am trying to send an email contains a fixed message and below it a formatted HTML table which gets the range values only if the total column "row[23]" is not empty, which means he's on shift.我正在尝试发送一封电子邮件,其中包含一条固定消息,其下方是一个格式化的 HTML 表,该表仅在总列“row[23]”不为空时才获取范围值,这意味着他正在轮班。

Simply I am trying to send the productivity to my team in a table containing the members in duty, in the Google Sheet formula to reflect the internal productivity, but I need the script to only contain the row with values in the table format, I've tried to create a new HTML page and link it with the .gs script, I've tried to use library, I've tried to generate formatted HTML table script using websites and combine them.只是我试图在包含值班成员的表格中将生产力发送给我的团队,在 Google Sheet 公式中反映内部生产力,但我需要脚本只包含具有表格格式值的行,我我尝试创建一个新的 HTML 页面并将其与 .gs 脚本链接,我尝试使用库,我尝试使用网站生成格式化的 HTML 表格脚本并将它们组合起来。

function sendEmails2() {

var sheet = SpreadsheetApp.getActiveSheet();

var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet6')

var startRow = 1; 

var numRows = sheet.getLastRow() 

var dataRange = sheet.getRange('A2:x18' );

var data = dataRange.getValues();

for (var i = 0; i < data.length; ++i) {


var row = data[i];

 var emailAddress = 'sherif.gamal1611@gmail.'

var message = "Hi team, kindly check our prod till now as below " 

var Date= row[0];

var subject = 'Productivity Report' + " " + Date;

if (row[23] !="" );  {

//var htmltable =[];

var TABLEFORMAT = 'cellspacing="10" cellpadding="10" dir="ltr" border="1" style="width:100%;table-layout:fixed;font-size:10pt;font-family:arial,sans,sans-serif;border-collapse:collapse;border:1px solid #ccc;font-weight:normal;color:black;background-color:white;text-align:center;text-decoration:none;font-style:normal;'

var html table = '<table ' + TABLE FORMAT +' ">';


for (row = 0; row<data.length; row++){

 htmltable += '<tr>';

 for (col = 2 ;col<data[row].length; col++){



  if (data[row][col] === "" || 0) {htmltable += '<td>' + '' + '</td>';} 
 else
  if (row === 0)  {
  htmltable += '<th>' + data[row][col] + '</th>';
 }

else {htmltable += '<td>' + data[row][col] + '</td>';}
}

   htmltable += '</tr>';
 }

  htmltable += '</table>';
   Logger.log(data);
  Logger.log(htmltable);


  MailApp.sendEmail(emailAddress, subject, message,{ htmlBody: htmltable});

   SpreadsheetApp.flush();
 }
}

The spacing and padding in the mail I receive is in a bad shape, I wonder if it's possible to be aligned and have the same format in the sheet and the mail to contain a message before the HTML table and the table to only contains the rows which has values in the total column row[23] " column X".我收到的邮件中的间距和填充形状不好,我想知道是否可以在表格和邮件中对齐并具有相同的格式以在 HTML 表格之前包含一条消息,而表格仅包含行它在总列行 [23]“X 列”中具有值。

把所有东西都放在一张桌子上,然后让你的初始信息周围的边界清晰

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM