Cloud Stack Ninja

Hello I am trying to set a date into Google Doc's document header. Now, here is the code I got so far but it won't change the current date inside my document's header as I close the document and re-open it any ideas what might be wrong with this code?

function onOpen() {
   var date = Utilities.formatDate(new Date(), "GMT-6", "dd-MM-yyyy"); 
   var pattern = "\\b\\d{2}\\.\\d{2}\\.\\d{4}\\b"; 
   var header = DocumentApp.getActiveDocument().getHeader();
   header.editAsText().replaceText(pattern, date);
}  

Also please note that I do have a date in this format inside my header: 15-10-2020. But this should update to give me today's date. However, that's not happening.

Thanks



Read more here: https://stackoverflow.com/questions/64395380/how-to-insert-date-into-google-header-using-app-script

Content Attribution

This content was originally published by mrRay at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: