In Google Sheets, after selecting a series of rows and right clicking on one of them, there is an option under Row Height that is Fit to Data. I would like to do this in a script.
All of my searching says no but I am hopeful. Columns are covered nicely but rows do not appear to be covered.
Thank you.
From what I know it isnt possible to have the rows automatically fit to data, this can only be done for columns with autoResizeColumn().
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
sheet.getRange('a1').setValue('Whenever it is a damp, drizzly November in my soul...');
// Sets the first column to a width which fits the text
sheet.autoResizeColumn(1);
However, if you know how much space your data will take you can just use a setRowHeight(). I think this is the only option you have for rows, columns seemed to be the prefered part to auto-fit.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Sets the first row to a height of 200 pixels
sheet.setRowHeight(1, 200);
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With