在iOS中通过onEdit复选框触发Google Apps脚本功能

zzwlnbp8  于 2023-03-31  发布在  iOS
关注(0)|答案(1)|浏览(100)

我有一个单元格(A1)包含一个复选框。我想让一个脚本函数只有在复选框被选中(true)的情况下才能在编辑上工作。我该怎么做?
我已经尝试了所有的解决方案,我可以找到的SO,但不幸的是没有一个为我工作。简单的脚本:

var response = UrlFetchApp.fetch(url + url_ext + sheet.getSheetId(), {                                 
        headers : {
            'Authorization' : 'Bearer ' + token
        }
    }).getBlob().setName(sheet.getName() + " " + date + ".pdf");

sheet_as_pdf_blob_document=response;

 
  var folder = DriveApp.getFolderById("bunchofrandomcharacters");
  backupFile = folder.createFile(sheet_as_pdf_blob_document);

// Here we send the email

function sendReport() {
 
   var message = {
    to: recipient,
    subject: subject + " " + date,
    body: body,
    name: nameOfSender,
    attachments: [sheet_as_pdf_blob_document]
  }

   MailApp.sendEmail(message);
w8rqjzmb

w8rqjzmb1#

试试这个:

function onEdit(e) {
  var sheet = e.range.getSheet();
  var sheetName = "Sheet1"; // Replace this with the name of the sheet containing the checkbox
  var checkboxCell = "A1"; 

  if (sheet.getName() !== sheetName) {
    return;
  }

  var editedRange = e.range;
  var editedCell = sheet.getRange(checkboxCell);

  if (editedRange.getA1Notation() === checkboxCell) {
    var checkboxValue = editedCell.getValue();

    if (checkboxValue) {
      //Here you can include the code you want to run if the checkbox is checked
    }
  }
}

相关问题