Google App Script HTML表格样式

奇杰诺

我已经在GAS中创建了一个功能,该功能可以从Google表格中获取数据并根据特定人员发送单独的电子邮件;然后该功能循环到下一个人并继续浏览数据。

我现在遇到的问题是格式化通过遍历数据创建的HTML表的格式。运行此数据时,数据以表格格式显示,但无法添加边框,颜色等。我目前在TABLEFORMAT变量下具有样式,但是我也尝试过将样式标签放入表中,th,td,tr标签,但似乎忽略了它。但是,我将输出放入HTML模拟器中,结果以我想要的方式显示出来。

有谁知道为什么这不适用于gs文件?另外,我正在尝试使cashGoalPosition为美元格式。先谢谢您的帮助; 我一直在为此绞尽脑汁,似乎无法弄清楚。

function Auto_Email(){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var shData = ss.getSheetByName("E-mail Data");
  var shEmail = ss.getSheetByName("E-mail List");
  var dataRange = shData.getDataRange(); // Fetch values for each row in the Range.
  var emailRange = shEmail.getDataRange(); //fetch values for email list
  var data = dataRange.getValues();
  var nameData = emailRange.getValues();
  var lastCol = dataRange.getLastColumn();

   for (var i = 1; i < nameData.length; i++) {
      var rows = nameData[i];
      var emailAddress = rows[2];//position of email header -1
      var fullName = rows[1]; //position of name header -1
      var firstName = rows[3]// the first name only
      var cashGoalPosition = rows[0].toString(); //position of billing goal -1
      var subject = firstName+"'s Cash Goal";
      var htmltable = '';
      var htmlmessage = "";
     var TABLEFORMAT = '<!DOCTYPE html><html><style>table {border-collapse:collapse} table,td,th{border:1px solid black}</style>'
      var pre_html = '<p>Dear '+firstName+',</p><p>Your new balance is <b>'+cashGoalPosition+'</b>. Below is a list of the invoices past due or due in the current month.</p><table style="width:100.0%"><tbody>'
      var post_html = '<p>Regards,<br>John</p></html>'

      for (row = 0; row<data.length; row++)
      { 
        for (col = 0 ;col<data[row].length; col++){
          if (row == 0 && col == 0) {htmltable += '<tr><th>' + data[row][col] + '</th>';}
          else
            if (row == 0 && col == lastCol - 1) {htmltable+= '<th>' + data[row][col] + '</th></tr>';}
          else
            if (row == 0) {htmltable+= '<th>' + data[row][col] + '</th>';}
          else
            if (data[row][0] == fullName && col == 0) {htmltable += '<tr><td>' + data[row][col] + '</td>';}
          else
            if (data[row][0] == fullName && col == lastCol -1) {htmltable += '<td>' + data[row][col] + '</td></tr>';}
          else
            if (data[row][0] == fullName) {htmltable += "<td>" + data[row][col] + "</td>";}
}

      }

     htmltable += '</tbody></table>';
     htmlmessage = TABLEFORMAT + pre_html + htmltable + post_html;


     Logger.log(htmlmessage)
MailApp.sendEmail(Session.getActiveUser().getEmail(), subject,'' ,{htmlBody: htmlmessage})
      }(i);
   }
Tanaike

<style>htmlBodyGmail上似乎不起作用我认为它可能会被删除。因此,请使用带有样式的表格标签。

在你的情况,<style>table {border-collapse:collapse} table,td,th{border:1px solid black}</style>并且<table style="width:100.0%">可以转换为<table style="width: 100%;border-collapse: collapse;border: 1px solid black">

修改后的脚本如下。

来自:

var TABLEFORMAT = '<!DOCTYPE html><html><style>table {border-collapse:collapse} table,td,th{border:1px solid black}</style>'
var pre_html = '<p>Dear '+firstName+',</p><p>Your new balance is <b>'+cashGoalPosition+'</b>. Below is a list of the invoices past due or due in the current month.</p><table style="width:100.0%"><tbody>'

至 :

var TABLEFORMAT = '<!DOCTYPE html><html>'
var pre_html = '<p>Dear '+firstName+',</p><p>Your new balance is <b>'+cashGoalPosition+'</b>. Below is a list of the invoices past due or due in the current month.</p><table style="width: 100%;border-collapse: collapse;border: 1px solid black"><tbody>'

如果我误解了您的问题,对不起。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在多个Google表格之间共享App Script Web App

Google App Script 将 CSV 导入到 Google 表格

Google Script Web App HTML记录问题

如何使用 Google App Script 从 html 表单中获取数据

Google Sheets App Script Html onload 不起作用

加速电子表格的脚本(GAS - Google App Script & Google Sheets)

Google App Script:在 Google 表格中動態添加新行

Google App Script 如何将公式设置为 Google 表格单元格

Google App Script 如何将公式设置为 Google 表格单元格

Google App Script 权限,过多?

Google-app-script SyntaxError

Google App Script 捕获行号

Google App Script:默认情况下未为新电子表格启用 Google 表格插件

如何使用App Script / JavaScript访问Google表格上的第二个标签?

在App Script中将.XLS转换为Google表格的最有效方法是什么?

是否可以使用 Google App Script 更改图表边框的颜色?[谷歌表格]

Google App Script - 使用 fetch 循环获取 API 响应并写入电子表格

Google App Script:如何显示带有模板化 HTML 链接的 Google Drive 文件

如何使用Google App Script将格式化后的文本从Google表格单元格保存到.rtf?

Google App Maker html 模板中的表格格式

使用 Google App Script 從一個電子表格跳轉到另一個電子表格

Google Sheets App Script If Else 不工作

Google App Script URLFetchApp.fetch 超时

Google Apps Script Multiple Search with Drive App

Google App Script - 列出所有包含

Google App Script 循环遍历值数组

生成的 HTML 代码未在电子邮件正文中正确显示(Google App Script)

将变量从 Code.gs 传递到 Google App Script 中的 html

用於從電子表格數據創建餅圖的 Google App Script 代碼未顯示