javascript - 记录时如何将布尔值记录为未定义的复选框?
问题描述
我正在尝试记录第 11 列的检查变量的值,它是一个复选框,如果勾选或未勾选,则应显示为真或假。但是,我收到一条日志,说该值未定义,我不太确定这是为什么。
有人可以帮忙吗?我已发表评论供您参考。
function sendEmail() {
//setup function
var ActiveSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var StartRow = 2;
var RowRange = ActiveSheet.getLastRow() - StartRow + 1;
var WholeRange = ActiveSheet.getRange(StartRow,1,RowRange,11);
var AllValues = WholeRange.getValues();
var message = "";
for (i in AllValues) {
var CurrentRow = AllValues[i];
var EmailSent = CurrentRow[13];
//problem here
var check = CurrentRow[11];
Logger.log(check)
if (EmailSent == "sent")
continue;
//set HTML template for information
message +=
"<p><b>Timestamp by: </b>" + CurrentRow[1] + "</p>" +
"<p><b>Requester Email: </b>" + CurrentRow[2] + "</p>" +
"<p><b>Star Rating: </b>" + CurrentRow[3] + "</p>" +
"<p><b>Request Category: </b>" + CurrentRow[4] + "</p>" +
"<p><b>Description: </b>" + CurrentRow[5] + "</p>" +
"<p><b>Label: </b>" + CurrentRow[6] + "</p>" +
"<p><b>Ticket ID: </b>" + CurrentRow[7] + "</p>" +
"<p><b>Comment: </b>" + CurrentRow[8] + "</p>" +
"<p><b>Status: </b>" + CurrentRow[9] + "</p><br><br>";
var setRow = parseInt(i) + StartRow;
ActiveSheet.getRange(setRow, 13).setValue("sent");
}
var SendTo = "email@email.org.au" + "," + "email@email.org.au";
var Subject = "CT IT feedback";
MailApp.sendEmail({
to: SendTo,
cc: "",
subject: Subject,
htmlBody: message,
});
}
解决方案
如上所述,如果您从工作表中获取值,您将需要考虑使用嵌套 for 循环进行循环。我不熟悉您在代码段中使用的那些功能,但为了学习,我在下面提供了一个如何逐步完成工作表的示例。
请参见下面的示例。
var sheet = [
[1,2,3,4],
[5,6,7,8],
[9,10,11,12]
];
// Think of the above array as your sheet.
// You will step go 1, 2, 3, 4 and then step down a row
// to 5, 6, 7, 8 and so on.
var rows = sheet.length;
var rowCount;
for(var i = 0; i < rows; i++) {
rowCount = 0;
for(var j = 0; j < sheet[i].length; j++) {
rowCount += sheet[i][j];
}
// Finished calculating the row.
console.log(rowCount);
}
推荐阅读
- c++ - boost::spirit::x3 中的通用解析器生成器
- python - 从 python 中重新启动 ipyparall 引擎
- python - 无法使用 Django 连接到 firebird 数据库
- excel - VBA - 删除临时文件中的查询
- javascript - Bootstrap 4更改特定元素的工具提示颜色
- flutter - json.decode 不转换地图
> - firebase - 可以在 arrayUnion 方法中传递 Firestore DocumentReference 吗?
- git - 在 GCM 调用期间任何 git 命令都会挂起
- python - 将 PDT 区域中的时间戳转换为日期时间 - Python
- python - 使用 Makefile 和 Docker 和 Python 部署到 heroku