简体   繁体   中英

Google Apps Script - Bookmark Elements of Table, Table Cell, Table Row in Google Docs

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

Selecting all table cells from the table:

在此处输入图像描述 在此处输入图像描述

Select a table cell:

在此处输入图像描述 在此处输入图像描述

Selecting table column from bottom to top: 在此处输入图像描述 在此处输入图像描述

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在此处输入图像描述

Column only在此处输入图像描述

Single table cell在此处输入图像描述

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