Thursday, 9 March 2023

Google Sheet + Apps Script : Day1

Created a program to change each strings containing cells of first column into hyperlinks redirecting to itself : 

function selfRefrencingHyperlinkMaker() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[1];
  //  var sheet = ss.getSheetByName("SheetName"); 
  var row;
  var startRowAt=2;
  var endRowAt=150;
  for ( row =startRowAtrow<endRowAtrow++ ) {
    var range = sheet.getRange(row,1);
    var values = range.getValues();
      if(values[0][0].length >0){
        var richValue = SpreadsheetApp.newRichTextValue()
                        .setText(values)
                        .setLinkUrl("#gid="+sheet.getSheetId()+"&range=A"+row)
                        .build();
        range.setRichTextValue(richValue)
      }
  }
}

No comments:

Post a Comment