setActiveCell on all sheets within a spreadsheet. Google Apps Script

后端 未结 1 1007
花落未央
花落未央 2021-01-24 02:45

I have a Google spreadsheet with multiple sheets. I would like the cursor to be set to a particular cell onOpen for all tabs. Each cell of the first row represents

相关标签:
1条回答
  • 2021-01-24 03:26

    Looks like you need to make a call to SpreadsheetApp.flush() when you loop over the sheets collection:

    function onOpen() {
      SpreadsheetApp.getActive().getSheets().forEach(function (s) {
        s.setActiveSelection("B4");
        SpreadsheetApp.flush(); // Force this update to happen
      });
    }
    

    My guess is Apps Script's execution engine optimizes the writes to a single call, and in that single call only one active selection can be made. Calling flush forces 1 call per sheet to be updated.

    0 讨论(0)
提交回复
热议问题