-
-
Save andreyka26-git/106ffc3bca0985295dfbfa6019ef6245 to your computer and use it in GitHub Desktop.
Google Docs Add today's date with heading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onOpen() { | |
var ui = DocumentApp.getUi(); | |
ui.createMenu('Services') | |
.addItem('Add Day', 'addNewDay') | |
.addToUi(); | |
} | |
function formatTwoDigit(n) { | |
return n < 10 ? '0' + n : '' + n; | |
} | |
function addNewDay() { | |
let cursor = DocumentApp.getActiveDocument().getCursor(); | |
if (!cursor) { | |
return; | |
} | |
let date = new Date(); | |
let dateStr = formatTwoDigit(date.getDate()) + '.' + (formatTwoDigit(date.getMonth() + 1)) + '.' + date.getFullYear(); | |
let element = cursor.insertText(dateStr); | |
if (element) { | |
element.setBold(true); | |
let parent = element.getParent(); | |
let style = {}; | |
style[DocumentApp.Attribute.HEADING] = DocumentApp.ParagraphHeading.HEADING4; | |
parent.setAttributes(style); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment