Useful Google Apps Script snippets to easily integrate in your Apps Script project. This library is design to be simple and easy to understand for beginners, by reducing the amount of codes it would take to get a tasks done and implement the most used function in one line of code.
It is important to enabled the Drive API from both Apps Script and the Google Cloud Platform API Dashboard.
You can use the library using the project ID.
1cyf4-wSESVKfkNR2xfDynYgE2nJ3P4M5SVoMqRd3EyQUajUCQLiU1-Z8 and SnippetApp as the identifier.
SnippetApp.user().firstName()
SnippetApp.sheet().getJSON('1abcdefghijklmnopqrstuv', 'Sheet1')
SnippetApp.calculate().months('04/15/2015', '07/25/2018');
Displays the user's first name.
var user = SnippetApp.user();
var firstName = user.firstName();
Or
SnippetApp.user().firstName();
Displays the user's last name.
SnippetApp.user().lastName();
Displays the user's full name.
SnippetApp.user().fullName();
Displays the user's email.
SnippetApp.user().email();
Displays the user's profile image using the document ID.
SnippetApp.user().profileImage('1abcdefghijklmnopqrstuvwxyz');
Displays the user's domain name using the document ID.
SnippetApp.user().domainName('1abcdefghijklmnopqrstuvwxyz');
Displays the sheet data in JSON format.
SnippetApp.sheet().getJSON('1abcdefghijklmnopqrstuvwxyz', 'sheet1', '2');
Generate a PDF file from the sheet.
SnippetApp.sheet().getPDF('1abcdefghijklmnopqrstuvwxyz', 'A', 'E');
Re-arrange sheets in alphabetical order.
SnippetApp.sheet().oderSheetByName('1abcdefghijklmnopqrstuvwxyz');
Displays today's date in different format.
SnippetApp.date().newDate('MM/dd/yyyy');
Displays today's time.
SnippetApp.date().newTime('HH:mm:ss');
Format dates or time
SnippetApp.date().format('01/01/2020', 'MM/dd/yyyy');
Calculate number of years between to dates.
SnippetApp.calculate().calculateYears('01/01/1980', '01/01/2020');
Calculate number of months between two dates.
SnippetApp.calculate().calculateMonths('01/01/1980', '01/01/2020');
Calculate number of days between two dates.
SnippetApp.calculate().calculateDays('01/01/1980', '01/01/2020');
Calculate number of hours between two dates.
SnippetApp.calculate().calculateHours('01/01/1980', '01/01/2020');
MM/dd/yy example: 01/01/20
MM/dd/yyyy example: 01/01/2020
MM/dd/yyyy HH:mm:ss example: 01/01/2020 23:59:59
HH:mm example: 23:59
HH:mm:ss example: 23:59:59
hh:mm example: 11:59
hh:mm:ss a example: 11:59:59 PM
1abcdefghijklmnopqrstuvwxyz
01/01/2020
01/01/2020
1abcdefghijklmnopqrstuvwxyz