Skip to content

Instantly share code, notes, and snippets.

@brainysmurf
Last active October 13, 2015 20:35
Show Gist options
  • Save brainysmurf/27e290ae2a87dbe50439 to your computer and use it in GitHub Desktop.
Save brainysmurf/27e290ae2a87dbe50439 to your computer and use it in GitHub Desktop.
README Table Maker.md

A simple Google Document that helps you make tables. Useful for teachers.

  • You can simply make a copy of this document and follow the instructions.
function onOpen() {
var ui = DocumentApp.getUi();
ui.createMenu('Actions')
.addItem('Make Table', 'appendTable')
.addToUi();
ui.alert(
'How this works:',
'Type or paste any text. Blank lines indicate where to make a new row. Then choose "Make Table" from the "Actions" menu.',
ui.ButtonSet.OK);
}
function appendTable() {
var body = DocumentApp.getActiveDocument().getBody();
var text = body.getText();
var blankLines = new RegExp("\n{2}")
var blocks = text.split(blankLines);
var cells = [];
blocks.forEach(function (item, index, arr) {
cells.push(item.split("\n"));
});
body.appendTable(cells);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment