首页 > 解决方案 > 谷歌脚本中的 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();
                         
                         }

}

标签: google-apps-scriptgoogle-sheets

解决方案


推荐阅读