Add Date into Google Doc at cursor Google Apps Script Lesson with Source Code

Add Date into Google Doc at cursor Document Apps Script Example

function onOpen() {

 const ui = DocumentApp.getUi();

 ui.createMenu(‘Adv’)

 .addItem(‘Add Date’,’adder’)

 .addToUi()

}

function adder(){

 const doc = DocumentApp.getActiveDocument();

 const cur = doc.getCursor();

 if(cur){

   const val = new Date();

   const temp = Utilities.formatDate(val,”GMT”, “yyyy-MM-dd”)

   const ele = cur.insertText(temp);

 }

}

Leave a Comment