Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
function showRow(doc){
var cache = getCache_();
try {
// if cache is set and id matches handle open row for editing
if ( && === doc.getId()){
doc.toast("Opened on row for editing...");
var sheet = doc.getSheetByName(cache.sheet);
if (sheet != null) {
sheet.hideRows(2, sheet.getLastRow()-1); // hide all the rows
sheet.showRows(cache.row); // show row
if (cache.header > 0){ // if header set show it
sheet.showRows(1, cache.header);
} else {
doc.setActiveRange(sheet.getRange("B1")); // set to row one first to keep above fold
PropertiesService.getUserProperties().setProperty("id", "");
// tried CacheService but seemed unreliabe
} else {
// default to showing all rows .. bit of a hacky way of doing it
var sheets = doc.getSheets();
for(var n in sheets){
sheets[n].showRows(1, sheets[n].getLastRow());
doc.toast("Showing all rows...");
} catch(e) {
PropertiesService.getUserProperties().setProperty("id", "");
doc.toast("Error on " +e.lineNumber + " "+e.message);
function getCache_(){
// tried CacheService but seemed unreliabe
// return CacheService.getUserCache().getAll(KEYS);
return PropertiesService.getUserProperties().getProperties();

This comment has been minimized.

Copy link

@cklann1 cklann1 commented Jan 23, 2017

Thanks for the example, Martin! Updated to fix minor syntax on row 16 (throwing an error on hideRow()).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment