如何在电子邮件中粘贴带有Google脚本/Google表格宏的表格? [英] How to paste in an email a table with google script/google sheets Macros?

查看:116
本文介绍了如何在电子邮件中粘贴带有Google脚本/Google表格宏的表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此Macro可以向某些人发送电子邮件.问题在于它将表粘贴为值,而不是表格式.我需要将表格粘贴为表格.

I have this Macro to send emails to some people. The problem is that it pastes the table in values, not in table format. I need to paste the table as a table.

    function Mails() {
 var values = SpreadsheetApp.getActiveSheet().getDataRange().getValues();
 var filas= values[0][1];
 var columnas= values[1][0];

 var ss = SpreadsheetApp.getActiveSpreadsheet();
 ss.setActiveSheet(ss.getSheetByName("Enviar"));
 var sheet = SpreadsheetApp.getActiveSheet();
 var dataRange = sheet.getRange(2,4,filas,columnas);
 var data = dataRange.getValues();

 for (i in data) {
 var rowData = data[i];
 var emailAddress = sheet.getRange(1, 3).getValue();
 var destinatario = rowData[0];
 var sigla1 = sheet.getRange(2,4,filas,columnas).getValues();
 var mensaje = 'Estimado ' + destinatario + ',\n\n' + sigla1 ;
 var asunto = 'Mensajes Pendientes';
 MailApp.sendEmail(emailAddress, asunto, mensaje);
 }
}

function onOpen () {
var spreadsheet = SpreadsheetApp.getActive();
var menuItems = [
{name: 'Send Emails', functionName: 'Mails'}
];
spreadsheet.addMenu('Enviar Emails', menuItems);

}

问题是此行var sigla1 = sheet.getRange(2,4,filas,columnas).getValues(); 我必须将其粘贴为表格,而不是值.我该怎么办?

The problem is this line var sigla1 = sheet.getRange(2,4,filas,columnas).getValues(); I have to paste it as a table, not in values. How can i do that?

谢谢

我正在尝试使用此代码..但是它不起作用..

I'am trying with this code now.. but it doesn't function..

function Mails() {

 var ss = SpreadsheetApp.getActiveSpreadsheet();
 ss.setActiveSheet(ss.getSheetByName("Enviar"));
 var sheet = SpreadsheetApp.getActiveSheet();

 var values = SpreadsheetApp.getActiveSheet().getDataRange().getValues();
 var filas= values[0][1];
 var columnas= values[1][0];

 var recipient = sheet.getRange(1, 3).getValue();
 var subject = 'Estimado';

 var vA=SpreadsheetApp.getActive().getSheetByName('Enviar').getDataRange().getValues();
 var html="<style>th,td{border:1px solid black;}<table>";
 for(var i=0;i<vA.length;i++) {
    html+="<tr>";
    for(var j=0;i<vA[i].length;j++) {
      if(i==0) {
        html+=Utilities.formatString('<th>%s</th>', vA[i][j]);
      }else{
        html+=Utilities.formatString('<td>%s</td>', vA[i][j]);
      }
    }
    html+="</tr>";
  }

  GmailApp.sendEmail(recipient, subject, null, {htmlBody:html})

}

function onOpen () {
var spreadsheet = SpreadsheetApp.getActive();
var menuItems = [
{name: 'Send Emails', functionName: 'Mails'}
];
spreadsheet.addMenu('Enviar Emails', menuItems);

}

此处您有一张我需要通过电子邮件发送的图片.

行随数据而变化,因此表取决于一天中的操作次数.

The rows change with the data, so the table depend of how many operations are in the day..

推荐答案

HTML表转换为电子邮件

function sendHtmlTableViaEmail() {
  var vA=SpreadsheetApp.getActive().getSheetByName('name').getDataRange().getValues();
  var html="<style>th,td{border:1px solid black;}<table>";
  for(var i=0;i<vA.length;i++) {
    html+="<tr>";
    for(var j=0;i<vA[i].length;j++) {
      if(i==0) {
        html+=Utilities.formatString('<th>%s</th>', vA[i][j]);
      }else{
        html+=Utilities.formatString('<td>%s</td>', vA[i][j]);
      }
    }
    html+="</tr>";
  }
 //You have to add the code for recipient and subject
  GmailApp.sendEmail(recipient, subject, null, {htmlBody:html})

}

这篇关于如何在电子邮件中粘贴带有Google脚本/Google表格宏的表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆