Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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