google-apps-script - 谷歌脚本中的 range.uncheck() 不起作用
问题描述
我需要准备好紧急通知发送给我的老板。我将这些通知存储在我的 Google Drive 中,并使用由触发器触发的脚本发送它们onEdit
。为了防止无意的电子邮件,我有第二个“安全”复选框,需要在脚本运行之前检查它。我想使用该range.uncheck()
方法取消选中“安全”复选框,但它不起作用。我正在寻求帮助,因为我还有其他uncheck()
效果很好的语句,而且我不明白为什么在脚本运行后这个“安全”复选框仍然处于勾选状态。
这是我的代码:
function myfunction() {
// Get active spreadsheet/source file
var srcSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
// Get the source sheet tab
var srcSheet = srcSpreadsheet.getSheets()[0];
var DM1wk1 = srcSheet.getRange('N19');
var safetyBox = srcSheet.getRange('K211');
if (DM1wk1.isChecked() && safetyBox.isChecked()) {
// Create the new sheet
var tempSheet = srcSpreadsheet.insertSheet('tempSheet');
// Hide all gridlines in the new sheet
tempSheet.setHiddenGridlines(true);
// *************************************************************************************************************************************
// Get desired data in the currently active sheet
var srcData1 = srcSheet.getRange('C9:K41');
// Copy and paste the desired range to copy from the currently active sheet to the new sheet
srcData1.copyTo(tempSheet.getRange(1,1),{contentsOnly:true});
srcData1.copyTo(tempSheet.getRange(1,1),{formatOnly:true});
srcData1.copyTo(tempSheet.getRange(1,1),SpreadsheetApp.CopyPasteType.PASTE_COLUMN_WIDTHS,false);
srcSheet.hideSheet();
// This section prepares variable info for an email
// Sets the recipient(s) of the email message
var emailAddress1 = "kl1990@mail.com";
// Sets the subject of the email message
var subjectPDF = "Current Schedule" + ".pdf";
// Sets the 'body message' of the email message
var bodyMessage = "Here is my schedule for this week";
// This section converts the new sheet into a pdf blob
// Make the pdf
var blob = DriveApp.getFileById(srcSpreadsheet.getId()).getAs("application/pdf");
// Set the title of the pdf
blob.setName(subjectPDF);
// **************************************************************************************************************************************
// This section assembles and sends the email
GmailApp.sendEmail(emailAddress1,subjectPDF,bodyMessage, {
htmlBody: bodyMessage,
attachments:[blob]
});
// Show hidden source sheet
srcSheet.showSheet();
// Delete new sheet ('Sheet')
srcSpreadsheet.deleteActiveSheet();
srcSheet.getRange('B1').activate();
srcSheet.getRange('N19').uncheck();
}
srcSheet.getRange('B1').activate();
srcSheet.getRange('R25').uncheck();
srcSheet.getRange('K211').uncheck();
}
}
解决方案
推荐阅读
- linux - bash - 获取正确处理新行的环境变量列表
- javascript - 将数据从父道具发送到子道具返回一个值,然后是未定义的功能组件
- javascript - Angular:无法读取 null 的属性(读取“cannotContainSpace”)
- typescript - 如何设置主 Vue 3 'app' 变量的 'type'
- node.js - 有人可以帮我做一个不和谐计数游戏吗
- python - 如何在 django 的某些视图中避免 THOUSAND SEPARATOR?
- python - `open` 不创建文件
- ado.net - 从 DataTable 到 DTO 的 AutoMapper
- c# - 从 ASP.NET MVC 操作方法返回文件 - 此请求已被阻止,因为敏感信息
- javascript - 如何在 JavaScript Annot3D PDF 中使 3D 对象移动?