Created
December 7, 2017 16:37
-
-
Save aflansburg/d307d072ca5b990e3280e5bb197b651f to your computer and use it in GitHub Desktop.
Remove empty rows from Google Sheets (Gsheets)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onInstall(e){ | |
onOpen(e); | |
} | |
function onOpen(e){ | |
var menu = SpreadsheetApp.getUi().createAddonMenu(); | |
menu.addItem('Remove Empty Rows', 'removeEmptyRows'); | |
menu.addToUi(); | |
} | |
function removeEmptyRows() { | |
showAlert('start'); | |
SpreadsheetApp.getActive() | |
.getSheets() | |
.forEach(function (s) { | |
c = 0; | |
s.getRange(1, 1, s.getMaxRows(), s.getMaxColumns()) | |
.getValues() | |
.forEach(function (r, j) { | |
if (r.toString() | |
.replace(/,/g, "") | |
.length == 0) { | |
s.deleteRow((j += 1) - c) | |
c += 1; | |
} | |
}) | |
}) | |
showAlert('end'); | |
} | |
function showAlert(locator){ | |
var ui = SpreadsheetApp.getUi(); | |
if (locator == 'start'){ | |
ui.alert('Empty rows will be deleted. Please leave the sheet open until the process completes.\nPress ok to continue.!'); | |
} | |
if (locator == 'end'){ | |
ui.alert('Empty rows removed.'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment