How to create hyperlink to range in Google Sheets App Script?

后端 未结 4 729
忘了有多久
忘了有多久 2020-12-10 09:39

I\'m trying to fill cells with hyperlinks to ranges in Google Sheets app script with the same desired outcome I would get had I done it in GUI. I managed to create hyperlink

4条回答
  •  佛祖请我去吃肉
    2020-12-10 09:59

    Yes, you can do this in App Script. Here's a very simple implementation where the HYPERLINK function is built and appended to a cell:

    function hyperlinkRange() {
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var sheet1 = ss.getSheetByName("Sheet1");
      var sheet2 = ss.getSheetByName("Sheet2").getSheetId();
    
      sheet1.getRange("A1").setValue('=hyperlink("#gid='+sheet2+'&range='+sheet1.getRange('A1:A10').getA1Notation()+'", "Click to jump to Sheet 2")');
    }
    

    You can combine this with loops to set a value of links across multiple sheets.

提交回复
热议问题