Placing checkboxes in Google Sheets using Apps Script

前端 未结 8 1038
遥遥无期
遥遥无期 2020-12-10 02:14

I know that checkbox is a relatively new feature in Google Sheets, so I\'m trying to find a way to automatically create checkboxes in cells.

So far, I haven\'t foun

8条回答
  •  旧时难觅i
    2020-12-10 03:09

    Easy:

    //There are two ways, using Range or using current cell or sheet or similar 
    //First is using current cell
    function VoF() {
      var spreadsheet = SpreadsheetApp.getActive();
      spreadsheet.getCurrentCell().offset(1, 0, 499, 1).setDataValidation(SpreadsheetApp.newDataValidation()
      .setAllowInvalid(true)
      .setHelpText('TRUE or FALSE')
      .requireCheckbox() //if you customize this is possible that you dont get the boxes and the verification data could fail,so keep them standar with TRUE and FALSE
      .build());
    };
    
    //Second is using Spreedsheet ranges
    
    function myFunction() {
      var spreadsheet = SpreadsheetApp.getActive();
      spreadsheet.getRange('G1:G11').activate();
      spreadsheet.getRange('G1:G11').setDataValidation(SpreadsheetApp.newDataValidation()
      .setAllowInvalid(false)
      .requireCheckbox()
      .build());
    };

提交回复
热议问题