Skip to content

Instantly share code, notes, and snippets.

@TaylorJadin
Last active March 2, 2020 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TaylorJadin/56a3c209e815ee3a8620342abef2c7d2 to your computer and use it in GitHub Desktop.
Save TaylorJadin/56a3c209e815ee3a8620342abef2c7d2 to your computer and use it in GitHub Desktop.
// Adds the custom menu to the active spreadsheet.
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Views')
.addItem('Show All', 'showAll')
.addItem('Contact Information View', 'contactInfoView')
.addItem('Calendar View', 'calendarView')
.addItem('Paperwork View', 'paperworkView')
.addItem('Tasks View', 'tasksView')
.addToUi();
}
function showAll() {
var spreadsheet = SpreadsheetApp.getActive();
// Select all columns in the spreadsheet
spreadsheet.getRange('A:CH').activate();
// Show all columns
spreadsheet.getActiveSheet().showColumns(spreadsheet.getActiveRange().getColumn(), spreadsheet.getActiveRange().getNumColumns());
};
// Define the hide column function
function hideColumn(columnLetter) {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange(columnLetter).activate();
spreadsheet.getActiveSheet().hideColumns(spreadsheet.getActiveRange().getColumn(), spreadsheet.getActiveRange().getNumColumns());
}
// Define all the other views
function contactInfoView() {
// First show all columns
showAll()
// Now hide the columns we don't want
hideColumn('A:A')
hideColumn('C:E')
hideColumn('I:I')
hideColumn('N:O')
hideColumn('P:Q')
hideColumn('T:AB')
hideColumn('AD:AJ')
hideColumn('AO:CH')
};
function calendarView() {
// First show all columns
showAll()
// Now hide the columns we don't want
hideColumn('A:A')
hideColumn('J:AH')
hideColumn('AI:AM')
hideColumn('AP:CH')
};
function paperworkView() {
// First show all columns
showAll()
// Now hide the columns we don't want
hideColumn('A:A')
hideColumn('C:E')
hideColumn('I:AH')
hideColumn('AI:AM')
hideColumn('BD:CH')
};
function tasksView() {
// First show all columns
showAll()
// Now hide the columns we don't want
hideColumn('A:A')
hideColumn('C:E')
hideColumn('H:BC')
hideColumn('BK:CH')
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment