Search code examples
javascriptgoogle-apps-scriptgoogle-sheetsgoogle-calendar-api

How to display a link inserted in Google Calendar on Google Sheet


After creating an event in Google Calendar, I inserted a link in the description box. How do I use apps script to display links properly in Google Sheets? When the link inserted in Google Calendar was linked to Google Sheet, it was displayed as shown below.

<a href="https://drive.google.com/file/d/1za_UIFwAgpVuN080jkjfacPGUWT3Eul--/view?usp=drive_link">Link</a>

I want it to display like this "Link" on google sheet.


Solution

  • You need to build a rich value. and then set it.

    function setURL(){
    
      var range = getActiveSheet().getActiveSheet().getRange("A2");
      var richValue = SpreadsheetApp.newRichTextValue()
       .setText("More information")
       .setLinkUrl("https://example.com")
       .build();
     range.setRichTextValue(richValue);
    }