【问题标题】:Creating a script in google sheet that creates a table and then send in an email to the recipient在 google sheet 中创建一个脚本来创建一个表,然后将电子邮件发送给收件人
【发布时间】:2022-11-18 18:37:21
【问题描述】:

我必须从活动行中拉出某些单元格。然后,当我单击按钮或超链接时,它会创建一个表格。然后我需要另一个按钮,它在表格中作为电子邮件发送给收件人。

有人可以建议一个简单的谷歌脚本来帮助我实现同样的目标吗?

我尝试从工作表和单元格中提取值,但无法插入到不同工作表中的特定表格。

【问题讨论】:

  • 欢迎,请阅读how-to-ask,并用一个具体的问题和你目前拥有的代码丰富你的帖子。 SO 不是一个只要求代码的地方。

标签: google-apps-script google-sheets


【解决方案1】:

请使用以下代码在 HTML 邮件中将一条或多条记录作为带标题的表格发送。您可以使用条件或复选框来选择行,也可以使用以下代码

  var currentRow = sheet.getActiveSelection().getRowIndex();
  var values = sheet.getRange("B"+currentRow+":AE"+currentRow).getValues();

获取当前行

//
//
function daily_mis(){
  var ss = SpreadsheetApp.getActiveSpreadsheet(); 
  var spsht = ss.getSheetByName("Spares");
  var sendto="email id";
  var message = "Report</b><br>";
  var message=message+"<table cellspacing='2' cellpadding='2' dir='ltr' border='1' style='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'"
      +"<tr>"
      +"<td bgcolor = '#ffffff', Align = 'center'>"+"Enq No"+"</td>"
      +"<td bgcolor = '#ffffff', Align = 'center'>"+"Enq Dt"+"</td>"
      +"<td bgcolor = '#ffffff', Align = 'center'>"+"Customer"+"</td>"
      +"<td bgcolor = '#ffffff', Align = 'center'>"+"Material"+"</td>"
      +"<td bgcolor = '#ffffff', Align = 'center'>"+"Offer Value"+"</td>"
      +"<td bgcolor = '#ffffff', Align = 'center'>"+"Offer Dt"+"</td>"
      +"<td bgcolor = '#ffffff', Align = 'center'>"+"Remarks"+"</td>"
      +"</tr>"
      +"<tr>"
  for (i=0;i<splr;i++)
     {
      if ( spvals[i][10] >= today-(24*3600*1000)) {
      //today = offer made today
      var message = message    
      +"<td bgcolor = '#ffffff', Align = 'center'>"+spvals[i][1]  +"</td>"
      +"<td bgcolor = '#ffffff', Align = 'center'>"+ Utilities.formatDate(spvals[i][2],"GMT+05:30", "dd-MMM")     +"</td>"
      +"<td bgcolor = '#ffffff', Align = 'center'>"+spvals[i][3].substring(0,15)  +"</td>"
      +"<td bgcolor = '#ffffff', Align = 'center'>"+spvals[i][6]  +"</td>"
      +"<td bgcolor = '#ffffff', Align = 'center'>"+spvals[i][8].toLocaleString('en-IN', { maximumFractionDigits: 0})  +"</td>"
      +"<td bgcolor = '#ffffff', Align = 'center'>"+ Utilities.formatDate(spvals[i][10],"GMT+05:30", "dd-MMM") +"</td>"
      +"<td bgcolor = '#ffffff', Align = 'center'>"+spvals[i][26] +"</td>"
      +"</tr>"
      +"<tr>"
      ;
      }
  }//for row
  message=message+"</table>"+".";
  var subject='Report - '+ Utilities.formatDate(today,"GMT", "dd-MM-yy");
  GmailApp.sendEmail( sendto , subject, "", 
    {  cc: "", 
      htmlBody: message ,
    });
}//function 
//

【讨论】:

    猜你喜欢
    • 2020-05-09
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 2018-11-19
    • 2020-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多