Skip to content

Instantly share code, notes, and snippets.

@JaKXz
Created June 14, 2017 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JaKXz/1c8225d50bf0660205ff71a6cca3b929 to your computer and use it in GitHub Desktop.
Save JaKXz/1c8225d50bf0660205ff71a6cca3b929 to your computer and use it in GitHub Desktop.
Google Docs script to find the last active-ish row in a table
function onOpen() {
// get the proparties we need to work with
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var tables = body.getTables();
// find the last table [since there's more than one somehow]
var table = tables[tables.length - 1];
var rows = table.getNumRows();
// this will approach rows - 1 as more of the table is filled in. totally arbitrary right now.
// TODO: or, find a way to get the first empty row.
var lastRow = table.getRow(rows - rows/4);
// for some reason with newPosition, you have to trainwreck the call from DocumentApp otherwise the compiler complains
// *shrug*
var position = DocumentApp.getActiveDocument().newPosition(lastRow, body.getNumChildren());
doc.setCursor(position);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment