Log Events From Google Calendar
- Create a new sheet
- Pre-populate a sheet with text
- Add data validation (drop-down list)
- Manual and automatic column/row size adjustments
- Add number formatting to a specific range
- Create colored and weighted cell borders
- Format text and cells (color, font weight, alignment, etc.)
- Insert formulas
- And More!
Create a New Sheet with Formatted Text and Cells
Code Snippet
function createNewSheet() {
//Step 1 - Activate spreadsheet
const spreadsheet = SpreadsheetApp.getActive();
//Step 1 (Optional) - Create new sheet
const newSheet = spreadsheet.insertSheet("Calendar Event Log");
//Step 2 - Declare variables for each cell
const calendarID = newSheet.getRange('a1').setValue("Calendar ID:");
const numOfDaysOut = newSheet.getRange('a2').setValue("Number of days out:");
const customFormulaCell = newSheet.getRange('a3').setValue('=if(B2="Custom", "Enter custom days out:", "")');
const eventNameCell = newSheet.getRange('d1').setValue("Event Name");
const startTimeCell = newSheet.getRange('e1').setValue("Start Time");
const endTimeCell = newSheet.getRange('f1').setValue("End Time");
const colorCell = newSheet.getRange('g1').setValue("Color");
const tagKeysCell = newSheet.getRange('h1').setValue("Tag Keys");
const creatorsCell = newSheet.getRange('i1').setValue("Creators");
const dateCreatedCell = newSheet.getRange('j1').setValue("Date Created");
const descriptionCell = newSheet.getRange('k1').setValue("Description");
const emailRemindersCell = newSheet.getRange('l1').setValue("Email Reminders (Minutes)");
const eventSeriesCell = newSheet.getRange('m1').setValue("Event Series");
const guestListCell = newSheet.getRange('n1').setValue("Guest List");
const eventIDCell = newSheet.getRange('o1').setValue("Event ID");
const lastUpdatedCell = newSheet.getRange('p1').setValue("Last Updated");
const locationCell = newSheet.getRange('q1').setValue("Location");
const popupRemindersCell = newSheet.getRange('r1').setValue("Popup Reminders (Minutes)");
const smsRemindersCell = newSheet.getRange('s1').setValue("SMS Reminders (Minutes)");
//Step 3 - Format cells
//Data validation dropdown list
spreadsheet.getRange('B2').setDataValidation(
SpreadsheetApp
.newDataValidation()
.setAllowInvalid(true)
.requireValueInList(['1 day', '7 days', '30 days', '60 days', '90 days', '180 days', '365 days', 'Custom'], true)
.build()
);
//Date format
spreadsheet.getRangeList(['E2:f', 'j1:j', 'p1:p']).activate();
spreadsheet.getActiveRangeList().setNumberFormat('M/d/yyyy H:mm:ss');
//Bold text
spreadsheet.getRangeList(['A1:A3', 'D1:s1']).activate();
spreadsheet.getActiveRangeList().setFontWeight('bold');
//Center text alignment
spreadsheet.getRange('D1:s1').activate();
spreadsheet.getActiveRangeList().setHorizontalAlignment('center');
//Manual column width adjustment
spreadsheet.getRange('D:s').activate();
spreadsheet.getActiveSheet().setColumnWidths(4,16,180);
//Fit to data column width adjustment
spreadsheet.getRange('A:A').activate();
spreadsheet.getActiveSheet().autoResizeColumns(1, 1);
//Set text font color
spreadsheet.getRange('A1').activate();
spreadsheet.getActiveRangeList().setFontColor('#0000ff');
spreadsheet.getRange('A3').activate();
spreadsheet.getActiveRangeList().setFontColor('#ff0000');
//Creates colored cell border with solid, medium border weight
spreadsheet.getRange('B1').activate();
spreadsheet.getActiveRangeList().setBorder(true, true, true, true, null, null, '#0000ff', SpreadsheetApp.BorderStyle.SOLID_MEDIUM);
spreadsheet.getRange('B3').activate();
spreadsheet.getActiveRangeList().setBorder(true, true, true, true, null, null, '#ff0000', SpreadsheetApp.BorderStyle.SOLID_MEDIUM);
}