Mark B
Mark B

Reputation: 423

Add hyperlink to a table cell within a Google Slides presentation

In my Google slideshow, I have a table. The table updates every 15 minutes. I have cells in this table that I want to include hyperlinks. I tried to manually enter a hyperlink by highlighting the text in the cell and right clicking, selecting "link". But when the table updates the hyperlinks gets removed. I've tried both setText() and insertText() in the script, both erase the links.

I've also looked into having the link automatically be re-added once the update was done, however slideshow tables don't have an insertLink command. Also, as this table is not actually a Google Spreadsheet, there is no setFormula() command.

Here is what I'm currently using to update the table. Works, just need hyperlinks added to the text.

FYI the links will be to other files in the Google Drive, if that matters...

var slide = SlidesApp.getActivePresentation().getSlides()[slideNo];
var table = slide.getTables();
var cell = table[0].getCell(row,4);
var trafficTime = convertTime(res["routes"][0]["summary"]["travelTimeInSeconds"]);
var trafficDelay = Math.round(res["routes"][0]["summary"]["trafficDelayInSeconds"]/60);  
var displayedTime = trafficTime + " +" + trafficDelay; 

cell.getText().clear();
cell.getText().insertText(0,displayedTime);

Upvotes: 1

Views: 735

Answers (1)

Tanaike
Tanaike

Reputation: 201673

  • You want to add a hyperlink to a text of a cell in a table on Google Slides.
  • You want to achieve this using Google Apps Script.

If my understanding is correct, how about this modification? Please think of this as just one of several possible answers.

Modification point:

  • In your case, TextRange returned from insertText can be used. For this, you can use the method of getTextStyle().setLinkUrl(URL).

Modified script:

When your script is modified, please modify as follows.

From:
cell.getText().insertText(0,displayedTime);
To:
var textRange = cell.getText().insertText(0,displayedTime);
textRange.getTextStyle().setLinkUrl(url);

or

cell.getText().insertText(0,displayedTime).getTextStyle().setLinkUrl(url);
  • In this casem, url is a string type like https://###sample###/.

References:

If I misunderstood your question and this was not the direction you want, I apologize.

Upvotes: 1

Related Questions