How to Create Clickable Link in HTML table using Sheet Converter function.

863 views
Skip to first unread message

[SA Portal] Data Manager

unread,
Jul 24, 2021, 4:39:29 PM7/24/21
to Google Apps Script Community
Hi 

Could anyone please help me in the below code to create a clickable link in html table using sheet converter function. In google sheet I have created a hyperlink function but while calling it through SheetConverter..convertRange2html(range). Its just displaying text instead of clickable link.

Here is my code - 

var range = update.getRange(4, 1, lr, 7);
    var htmlTable = SheetConverter.convertRange2html(range);

The hyperlink is at column 7

Please find screenshot for your reference.

Thanks,


1.png

cbmserv...@gmail.com

unread,
Jul 24, 2021, 8:11:38 PM7/24/21
to google-apps-sc...@googlegroups.com

The code to covert a spreadsheet blob to PDF is a program provided by base Google software. There may be a way to have it specify a link in it rather than just the text, but am not aware of such.

 

One suggestion I would have for you is rather than using PDF, why not covert the spreadsheet data to HTML? That would make it easy to insert in an email. You can make it as a HTML blob as well if you wish, it would be opened via a browser in that case rather than a PDF reader. Only downside to that is security procedures in some companies may prohibit this as that is a very easy way to send viruses to infect PCs as well.

 

So best way in my opinion is to use HTML and include it in the email that you are sending out.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/0308cbc4-72f4-4533-83a0-efec291db482n%40googlegroups.com.

cbmserv...@gmail.com

unread,
Jul 24, 2021, 9:03:32 PM7/24/21
to google-apps-sc...@googlegroups.com

Sorry my last reply was out of context. I mixed up my reply with other questions I saw earlier.

 

In your case, the use of SheetConverter library is ok if you understand how that library is setup. I do not have any experience with it. But here is a quick little script that does this manually rather than through a library.

 

Note there are no interface methods right now to pull a link from a range. So it is best to have your spreadsheet show the whole link itself as text. In your conversion to HTML, you can hide the link then if you wish by using “<a href=”link”>Some Text</a>” so that Some Text will show up as the link they can click.

 

Note script does the whole spreadsheet. If you want only a portion of it, just change how lastRow and LastColumn variables are being set.

 

function testTableHTML() {

  var s = SpreadsheetApp.getActiveSheet();

  var lastRow = s.getLastRow();

  var lastColumn = s.getLastColumn();

  var sheetData = s.getRange(11lastRowlastColumn).getValues();  

  // set headers

  var message = "<table><tr>";

  for (var i = 0i < lastColumni++)

  {

    message += "<th>" + sheetData[0][i] + "</th>"

  } 

  message += "</tr>";

  // now go through table and add all data, one line per row of data

  for (var j = 1j < lastRowj++)

  {

    message += "<tr>";

    for (var i = 0i < lastColumni++)

    {

      message += "<td>" + sheetData[j][i] + "</td>"

    } 

    message += "</tr>";    

  }

  message += "</table>";

  MailApp.sendEmail(thisEmail"Test HTML Table"message);

Reply all
Reply to author
Forward
0 new messages