Skip to content

Instantly share code, notes, and snippets.

@guenp
Created August 21, 2015 09:10
Show Gist options
  • Save guenp/c9ac77ffc4b78b68012b to your computer and use it in GitHub Desktop.
Save guenp/c9ac77ffc4b78b68012b to your computer and use it in GitHub Desktop.
Google script for creating auto header with date/time stamp in docs
function onOpen() {
// Add a menu with some items, some separators, and a sub-menu.
DocumentApp.getUi().createMenu('Utilities')
.addItem('New entry', 'insertDateStamp')
.addToUi();
}
/**
* Inserts the date at the current cursor location in boldface.
*/
function insertDateStamp() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var user = Session.getActiveUser().getEmail()
var date = Utilities.formatDate(new Date(), "GMT+2", "dd-MM-yyyy' @'HH:mm:ss"); // "yyyy-MM-dd'T'HH:mm:ss'Z'"
body.appendPageBreak();
var par = body.appendParagraph('<' + user + '> ' + date);
//par.setBold(true);
par.setHeading(DocumentApp.ParagraphHeading.HEADING3);
body.appendHorizontalRule();
var returnchar = body.appendParagraph("\r");
var position = doc.newPosition(returnchar.getChild(0), 1);
doc.setCursor(position);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment