mogsdad / SheetConverter

Google Apps Script library - interprets Google Sheets Formats, converts to formatted text or html
49 stars 25 forks source link

Links @ the html table #6

Open alxkutovoy opened 8 years ago

alxkutovoy commented 8 years ago

Hi David!

Hope you're doing well! Firstly, I'd like to say THANK YOU for your outstanding work and the SheetConverter in particular. You saved A LOT of time for me and numerous users. I really appreciate your effort and contribution!

May I kindly ask whether it might be possible in the nearest future to export tables that might contain links in some cells?

Thank you and have a wonderful day!

Alex

alxkutovoy@gmail.com

screen shot 2016-06-27 at 14 59 55 screen shot 2016-06-27 at 15 00 04

ChadEmory commented 4 years ago

This was not an option before but as of the June 2020 update, there is now a method to do this but might make for a lot of extra complications, it would depend on do we want to support only one hyper link per cell or multiple hyper links per cell (which is now possible)? I would vote only one per cell as multiple ones just seems like a lot on complications with little end results.

ChadEmory commented 4 years ago

OK, I worked out code to get the URL links of the data Range, code below, but I can't seem to work out where to inject the html code for the cells in the script. Any one have an idea?

Here is my code to gather the HTMLlinks for the range just place this code starting at line 225, the code will make an array with html that matches HTML in the data range and 0 (zero) where there is no URL.

* Code starts here *** // Get the UrlLinks for range var urlLinks = []; for (var row=startRow; row<lastRow; row++) { var w = []; for (var col=startCol; col<lastCol; col++) { var url = null; var url = sheet.getRange(row,col).getRichTextValue(); var urlString = null; if (url){ urlString = sheet.getRange(row,col).getRichTextValue().getLinkUrl(); } if ((url == null)|(urlString ==null)) { urlString = 0;} w.push(urlString); } urlLinks.push(w); } * Code ends here ***

rugbbyli commented 4 years ago

@ChadEmory i made a little changes to let the link included in html, add codes after line 294: https://github.com/mogsdad/SheetConverter/blob/1f11b8ddcc4cbb36d88d429e427e861b1e7eb960/SheetConverter/Code.gs#L294

        var richValue = range.getCell(row+1,col+1).getRichTextValue();
        var linkUrl = richValue && richValue.getLinkUrl();
        if(linkUrl) {
          cellText = `<a href="${linkUrl}" target="_blank">${cellText}</a>`;
        }

it was using in my local and not tested on a large scale, just provide an idea.

ChadEmory commented 4 years ago

@rugbbyli - When I try your code I get an illegal character on the next to the last line of your code -

cellText = <a href="${linkUrl}" target="_blank">${cellText}</a>;

ChadEmory commented 4 years ago

Worked out all the details to get this working an tested, put in a pull request to have added to the master code. #19

kikko616 commented 3 years ago

@ChadEmory Hi there, just checking if your request has been implemented in the master code of the main library yet, or are you using your own? Thanks!

ChadEmory commented 3 years ago

It as not been incorporated into the code here. I do have it in my code branch on github. Just export it and paste into your own script in Google and enjoy.