Ask Your Question
0

What is the method of adding RichLink (Chip Block) into Google Docs by means of Google App Script?

asked 2023-05-01 15:16:16 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-05-01 15:39:01 +0000

qstack gravatar image

Here are the steps to add a RichLink (Chip Block) into Google Docs using Google Apps Script:

  1. First, open a Google Doc and go to Tools > Script editor.

  2. In the Script editor, create a new script file and name it something like "AddRichLinkToDoc".

  3. Next, in the script file, add the following code to create a RichLink Block:

function createRichLink() {
    var richLink = {
        title: 'Google',
        link: 'https://www.google.com',
        description: 'Search the world\'s information, including webpages, images, videos and more.',
        thumbnailUrl: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'
    };
    var richLinkBlock = {
        richLink: richLink
    };
    return richLinkBlock;
}

This code creates a new RichLink object with the title, link, description, and thumbnail URL, and then returns a block object containing the RichLink.

  1. Now, add the following code to insert the RichLink into your document:
function insertRichLink() {
    var richLinkBlock = createRichLink();
    var selection = DocumentApp.getActiveDocument().getSelection();
    if (selection) {
        var element = selection.getSelectedElements()[0];
        var range = element.getElement().getParent();
        range.insertBlock(richLinkBlock);
    }
}

This code calls the createRichLink function to create a new RichLink block, gets the current selection in the document, and then inserts the RichLink block into the document.

  1. Finally, save your script and then run the insertRichLink function to add the RichLink to your document.

Overall, with these steps, you can easily add RichLink (Chip Block) to Google Doc using Google App Script.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-01 15:16:16 +0000

Seen: 20 times

Last updated: May 01 '23