opowell
opowell

Reputation: 587

add an <a> element to Google Document using Apps Script

I want to include a "properly formatted" mailto: link in a paragraph of text in my document:

"Please <a href="mailto:[email protected]">contact me</a> if you have any questions."

The only way I can think of doing this is with multiple Paragraphs and Styles, which I don't think would be an elegant solution. I was wondering if there was just some easier way of including an <a> tag directly in the document. The Text object has a setLinkUrl() method, but I'm not sure how to create a Text object! var link = "my link text" creates a String.

Upvotes: 2

Views: 1762

Answers (1)

zerogiant
zerogiant

Reputation: 194

A working solution using the paragraph class,

var par1a = doc.appendParagraph("Please ");
var link = doc.appendParagraph("Contact me ").setLinkUrl("mailto:[email protected]");
link.merge();
var par1b = doc.appendParagraph("if you have any questions.");
par1b.merge();

Upvotes: 4

Related Questions