Search code examples
google-apps-scriptgoogle-docs

Bookmark Elements of Table, Table Cell, Table Row


I want to achieve a bookmarking behavior like the example below using a custom script.

Selecting all table cells from the table:

enter image description here enter image description here

Select a table cell:

enter image description here enter image description here

Selecting table column from bottom to top: enter image description here enter image description here


Solution

  • This is what worked for me:

    function myFunction() {
      var doc = DocumentApp.getActiveDocument(); 
      var selection = doc.getSelection().getRangeElements();
      var pos = selection[0].getElement();
      doc.addBookmark(doc.newPosition(pos,0));
    }
    

    Screenshots:

    Full table enter image description here

    Column only enter image description here

    Single table cell enter image description here