Możliwe jest wstawienie dzisiejszej daty za pomocą makra.
Otwórz dokument Google i w menu Narzędzia wybierz Edytor skryptów . Spowoduje to otwarcie edytora skryptów Google, w którym można tworzyć makra dla Dokumentów Google.
Wklej ten skrypt i zapisz go jako makro daty lub coś w tym stylu: (dostępny również tutaj )
/**
* The onOpen function runs automatically when the Google Docs document is
* opened. Use it to add custom menus to Google Docs that allow the user to run
* custom scripts. For more information, please consult the following two
* resources.
*
* Extending Google Docs developer guide:
* https://developers.google.com/apps-script/guides/docs
*
* Document service reference documentation:
* https://developers.google.com/apps-script/reference/document/
*/
function onOpen() {
// Add a menu with some items, some separators, and a sub-menu.
DocumentApp.getUi().createMenu('Utilities')
.addItem('Insert Date', 'insertAtCursor')
.addToUi();
}
/**
* Inserts the date at the current cursor location in boldface.
*/
function insertAtCursor() {
var cursor = DocumentApp.getActiveDocument().getCursor();
if (cursor) {
// Attempt to insert text at the cursor position. If insertion returns null,
// then the cursor's containing element doesn't allow text insertions.
var date = Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd"); // "yyyy-MM-dd'T'HH:mm:ss'Z'"
var element = cursor.insertText(date);
if (element) {
element.setBold(true);
} else {
DocumentApp.getUi().alert('Cannot insert text at this cursor location.');
}
} else {
DocumentApp.getUi().alert('Cannot find a cursor in the document.');
}
}
Teraz odśwież lub ponownie otwórz dokument, a pojawi się nowy element menu: Narzędzia . W tym menu pojawia się element o nazwie Wstaw datę . Kliknij, aby wstawić dzisiejszą datę w pozycji kursora.
Aby zmienić format daty, musisz zmienić „format” użyty w skrypcie. Format może zawierać następujące znaki:yyyy-MM-dd'T'HH:mm:ss'Z'
Aby to wyjaśnić, ten skrypt po prostu wstawia dzisiejszą datę w miejscu kursora w dniu uruchomienia narzędzia. Nie jest to dokładnie to samo, co funkcja = Today () w Arkuszach Google, która aktualizuje datę do bieżącej daty za każdym razem, gdy otwierasz arkusz kalkulacyjny. Jednak ten skrypt zaoszczędzi ci trudu wyszukiwania daty i wpisywania jej w dniu wykonania skryptu.