How do I deselect an active cell when clicking on an image to run a script?

前端 未结 3 1925
再見小時候
再見小時候 2021-01-29 04:28

I have a spreadsheet-bound script that is invoked by clicking an image in the spreadsheet. I\'ve found that the script can be blocked if a cell that it needs to modify is active

3条回答
  •  天命终不由人
    2021-01-29 05:27

    I had the same problems, both the initial one and with the solution proposed by Mogsdad.

    I resolved it the following way:

    Before running any of the script, the first three lines get a different sheet opened and the spreadsheet gets flushed:

    var spreadsheet = SpreadsheetApp.getActive();
      spreadsheet.setActiveSheet(spreadsheet.getSheetByName('DIFFERENT SHEET NAME'), true);
      SpreadsheetApp.flush();
    

    The rest of the script follows.

    Then at the end of the script, I reopen the initial sheet with a simple:

    spreadsheet.setActiveSheet(spreadsheet.getSheetByName('ORIGINAL SHEET NAME'), true);
    

提交回复
热议问题