从包含整个格式和边框的电子表格发送电子邮件

时间:2016-04-25 10:11:08

标签: google-apps-script google-sheets

您好我正在尝试从谷歌电子表格向邮件发送一个表格,但所有我得到的是#34; [object Object]"在邮件中,这是我的脚本。

function sendEmail() {
  var s = SpreadsheetApp.getActive().getSheetByName('Summary');
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var range = ss.getActiveSheet().getDataRange();
  var range = s.getRange('A1:D8');
  var to = "srinath@example.com";
  var body = '';
  var htmlTable = SheetConverter.convertRange2html(range);
var body = "Here is the table:<br/><br/>"
     + htmlTable
     + "<br/><br/>The end."

  MailApp.sendEmail(to, 'Subject', {htmlBody: body});
};

我想将整个表格和格式发送到邮件正文中 我从这个链接Use MailApp to send formatted data from spreadsheet in htmlBody获得了Sheetconverter库 请帮帮我

1 个答案:

答案 0 :(得分:1)

在电子邮件正文中发送HTML时,您需要包含专门声明存在HTML正文的选项。

MailApp.sendEmail(email, 'Subject', body, {htmlBody: body})

{htmlBody: body}位是你失踪的地方。

修改后的代码:

function sendEmail() {
  var s = SpreadsheetApp.getActive().getSheetByName('Summary');
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var range = ss.getActiveSheet().getDataRange();
  var range = s.getRange('A1:D8');
  var to = "srinath@example.com";
  var body = '';
  var htmlTable = SheetConverter.convertRange2html(range);
var body = "Here is the table:<br/><br/>"
     + htmlTable
     + "<br/><br/>The end."

  MailApp.sendEmail(to, 'Subject', body, {htmlBody: body});
};