Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way within a Google Apps Script to set a row height to fit the data

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.

like image 767
TC Lawrence Avatar asked Dec 06 '22 13:12

TC Lawrence


1 Answers

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!

like image 87
Taum Avatar answered Dec 28 '22 05:12

Taum