How to add a hyperlink in a Google Docs using a Google Script

前端 未结 3 848
被撕碎了的回忆
被撕碎了的回忆 2020-12-31 06:36

I have always used the insertText() function, but now I want to write a link in my google docs. The ideal would be to be able to write in HTML, but I don\'t know how.. it se

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-31 07:06

    I am using this script, this is working Calomun 1 Row > 2.

        function InsertLink(e)
        {
          var actSht = e.source.getActiveSheet();
          if (actSht.getName() == ['SheetName']){
    
          var activeCell = actSht.getActiveCell(); //Detec the ActiveCell
    
          //var activeCell = event.range;
          var activeCellValue = e.value;
    
          var column = activeCell.getColumn();
          var colNums  = [1]; //Columns, whose edit is considered
          if(colNums.indexOf(column) == -1) return; //If column other than considered then return
    
          var row = activeCell.getRow();
          if(row < 2)   return; //If header row then return
    
          var length = String(activeCellValue).length;
    
          if (!e.value)
          {
            activeCell.setValue()
          }
          else if(length > 4)
          {
            activeCell.setValue('=HYPERLINK' + '("http://otrs/otrs/index.pl?Action=AgentTicketZoom;TicketNumber='+activeCellValue+'";"'+activeCellValue+'")'        );
          }
        }
        }
    

提交回复
热议问题