Javascript 通过电子邮件发送来自谷歌应用程序脚本的筛选结果
我有以下功能(顺便说一句,我是谷歌应用程序脚本的新手) 过滤器数据过滤工作表并返回与逻辑匹配的所有行。我希望能够通过电子邮件发送这些行。如果我运行这个,我会收到并发送电子邮件。(此外,为了简单起见,请将其缩短) 我可以看到这是一个对象,但我在他们的API上找不到任何东西,指出了如何将结果转换为实际值的正确方向 psJavascript 通过电子邮件发送来自谷歌应用程序脚本的筛选结果,javascript,google-apps-script,google-sheets,google-sheets-api,Javascript,Google Apps Script,Google Sheets,Google Sheets Api,我有以下功能(顺便说一句,我是谷歌应用程序脚本的新手) 过滤器数据过滤工作表并返回与逻辑匹配的所有行。我希望能够通过电子邮件发送这些行。如果我运行这个,我会收到并发送电子邮件。(此外,为了简单起见,请将其缩短) 我可以看到这是一个对象,但我在他们的API上找不到任何东西,指出了如何将结果转换为实际值的正确方向 ps 是的,如果我使用console.log filterData,我会得到正确的对象。有什么想法吗?您可以尝试使用join,因为您发送的数据是一个数组。将其转换为字符串以正确显示数据 样
是的,如果我使用console.log filterData,我会得到正确的对象。有什么想法吗?您可以尝试使用
join
,因为您发送的数据是一个数组。将其转换为字符串以正确显示数据
样本数据:
let filterData = thisSpreadsheet.filter(function (row, index) {
return row[11] >= 30;
});
// Preprocesses filterData before sending mail
filterData.forEach(function (row, index) {
filterData[index] = filterData[index].join(",");
});
filterData = filterData.join("\n");
if (filterData.length > 0) {
MailApp.sendEmail({
to: 'email@gmail.com',
subject: 'test',
body: filterData,
noReply: true
});
}
代码:
let filterData = thisSpreadsheet.filter(function (row, index) {
return row[11] >= 30;
});
// Preprocesses filterData before sending mail
filterData.forEach(function (row, index) {
filterData[index] = filterData[index].join(",");
});
filterData = filterData.join("\n");
if (filterData.length > 0) {
MailApp.sendEmail({
to: 'email@gmail.com',
subject: 'test',
body: filterData,
noReply: true
});
}
样本输出:
let filterData = thisSpreadsheet.filter(function (row, index) {
return row[11] >= 30;
});
// Preprocesses filterData before sending mail
filterData.forEach(function (row, index) {
filterData[index] = filterData[index].join(",");
});
filterData = filterData.join("\n");
if (filterData.length > 0) {
MailApp.sendEmail({
to: 'email@gmail.com',
subject: 'test',
body: filterData,
noReply: true
});
}
一个快速的答案是尝试用JSON.stringify()
包装filterData
,但不能修改它在邮件中的显示方式
代码:
let filterData = thisSpreadsheet.filter(function (row, index) {
return row[11] >= 30;
});
// Preprocesses filterData before sending mail
filterData.forEach(function (row, index) {
filterData[index] = filterData[index].join(",");
});
filterData = filterData.join("\n");
if (filterData.length > 0) {
MailApp.sendEmail({
to: 'email@gmail.com',
subject: 'test',
body: filterData,
noReply: true
});
}
body:JSON.stringify(filterData),
样本输出:
let filterData = thisSpreadsheet.filter(function (row, index) {
return row[11] >= 30;
});
// Preprocesses filterData before sending mail
filterData.forEach(function (row, index) {
filterData[index] = filterData[index].join(",");
});
filterData = filterData.join("\n");
if (filterData.length > 0) {
MailApp.sendEmail({
to: 'email@gmail.com',
subject: 'test',
body: filterData,
noReply: true
});
}
我找到了一种方法,因为这是一个对象数组,所以我将其转换为和HTML函数。如下 我传入了数组结果并添加了一些头
function makeTableHTML(myArray,tableHeaders) {
let result = "<table border=1>";
result += "<tr>";
for(var j=0; j<tableHeaders.length; j++){
result += "<td>"+tableHeaders[j]+"</td>";
}
result += "</tr>";
for(var i=0; i<myArray.length; i++) {
result += "<tr>";
for(var j=0; j<myArray[i].length; j++){
result += "<td>"+myArray[i][j]+"</td>";
}
result += "</tr>";
}
result += "</table>";
return result;
}
函数makeTableHTML(myArray,TableHeader){
让结果=”;
结果+=”;
for(var j=0;jt谢谢,但我认为Java对象只是一种误解脚本不知道如何处理它。我找到了一种方法。我会很快发布我的答案。答案很好。如果您希望它出现在表中,这也很有效。