gpt4 book ai didi

google-apps-script - 设置表格格式并通过电子邮件发送

转载 作者:行者123 更新时间:2023-12-03 08:09:44 32 4
gpt4 key购买 nike

我正在尝试发送一封包含表格的电子邮件,我已设法创建表格,但无法弄清楚如何复制格式(包括背景颜色和数字格式),因为某些单元格包含货币以及百分比和普通数字。

由于数据采用颜色编码,因此将这些数据复制到电子邮件中非常重要。

这是我的代码,如果有人能指出我正确的方向,那将非常有帮助,这是迄今为止我的代码......

function createTable(data){ 
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");

//To be looped in the future, 10 in range to be replaced with k
var dataRange = sheet.getRange(10,4,1,9);
var data = dataRange.getValues();

//Table Header
var table = "<html><body><br><table border=1><tr><th>Compliance Score</th><th>STSOR Value</th><th>STSOR %</th><th>ZZ lines</th><th>ZZ%</th><th>PI lines Counted</th><th>PI %</th><th>NRDS Value</th><th>NRDS %</tr></br>";

//table Body
for (var i = 0; i < data.length; i++){
cells = data[i]; //puts each cell in an array position
table = table + "<tr>";

for (var u = 0; u < cells.length; u++){
table = table + "<td>"+ cells[u] +"</td>";
}
table = table + "</tr>"


//Send the email:
MailApp.sendEmail({
to: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d9bca1b8b4a9b5bc99beb4b8b0b5f7bab6b4" rel="noreferrer noopener nofollow">[email protected]</a>",
subject: "Example",
htmlBody: table});
}
}

最佳答案

我相信您的目标如下。

  • 您想要创建一个包含单元格背景颜色和数字格式的 HTML 表格。

既然如此,下面的修改如何?

修改后的脚本:

function createTable() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var dataRange = sheet.getRange(10, 4, 1, 9);
var backgrounds = dataRange.getBackgrounds(); // Added
var data = dataRange.getDisplayValues(); // Modified
var table = "<html><body><br><table border=1><tr><th>Compliance Score</th><th>STSOR Value</th><th>STSOR %</th><th>ZZ lines</th><th>ZZ%</th><th>PI lines Counted</th><th>PI %</th><th>NRDS Value</th><th>NRDS %</tr></br>";
for (var i = 0; i < data.length; i++) {
cells = data[i];
table = table + "<tr>";
for (var u = 0; u < cells.length; u++) {
table = table + `<td style="background-color:${backgrounds[i][u]}">` + cells[u] + "</td>"; // Modified
}
table = table + "</tr>"
MailApp.sendEmail({
to: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="87e2ffe6eaf7ebe2c7e0eae6eeeba9e4e8ea" rel="noreferrer noopener nofollow">[email protected]</a>",
subject: "Example",
htmlBody: table
});
}
}

引用:

关于google-apps-script - 设置表格格式并通过电子邮件发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71171305/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com