简体   繁体   中英

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:me@me.com">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 .

A working solution using the paragraph class,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM