Google app script monitor spreadsheet selected ranges

前端 未结 2 774
耶瑟儿~
耶瑟儿~ 2021-01-28 05:11

I want to write a app script that can get the selected cells

and show it on the html input text.

example:

when I selected A1 cell, then the input text wi

2条回答
  •  萌比男神i
    2021-01-28 05:39

    I made this as a possible solution. The app script looks like this. It works quite well. Not sure if it is what you are looking for.

    function onOpen() {
      SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
          .createMenu('Custom Menu')
          .addItem('Show sidebar', 'showSidebar')
          .addToUi();
    }
    
    function showSidebar() {
      var html = HtmlService.createHtmlOutputFromFile('Page')
          .setTitle('My custom sidebar')
          .setWidth(300);
      SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
          .showSidebar(html);
    }
    
    function getActiveRange(){
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var sheet = ss.getSheetByName('Sheet1');
      var range = sheet.getActiveRange().getA1Notation();
      Logger.log(range)
      return range  
    }
    

    The side bar has function that calls every 200th of a second. Making it look like it is getting the data on mouse drag.

    
    
    
        
        
        
    
    
             
             
    
    
    

提交回复
热议问题