Skip to content

Instantly share code, notes, and snippets.

@ithinkihaveacat
Created December 21, 2017 15:30
Show Gist options
  • Save ithinkihaveacat/714fb833a94165714ed561388800421d to your computer and use it in GitHub Desktop.
Save ithinkihaveacat/714fb833a94165714ed561388800421d to your computer and use it in GitHub Desktop.
Google Sheets: Resize Cells
// Resize rows and columns to fit the data we're inserting. This requires special
// permission for some reason.
function setSizes() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheets = ss.getSheets();
for (var i=0; i < sheets.length; i++) {
var sheet = sheets[i];
var range = sheet.getDataRange();
var numRows = range.getNumRows();
for (var r=2; r <= numRows; r++) {
sheet.setRowHeight(r, 160);
};
[400, 120, 90, 70, 70, 70, 70].forEach(function (v, i) {
sheet.setColumnWidth(i + 1, v);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment