I didn't see anything in the documentation that would make me think this is a supported function. I'm writing to several sheets and visually it's difficult to see all the data without highlighting all the columns and autosizing with my mouse. I'd rather not have to do that everytime I run my script.
Is there a way to do this programmatically with app scripts? I saw the option to setColumnWidth, but how do I know how wide to set my columns when my text could vary from column to column.
==thanks for any help.
autoResizeColumn(columnPosition)
See the API for more details
There is now a new method called autoResizeColumn(columnPosition)
var s = SpreadsheetApp.getActive().getActiveSheet();
s.autoResizeColumn(6);
Autosizes the 6th column (a.k.a column "F").
See this stackoverflow answer https://stackoverflow.com/a/29930315/8458041
There's also a way to do multiple columns at once: autoResizeColumns(startColumn, numColumns)
var s = SpreadsheetApp.getActive().getActiveSheet();
s.autoResizeColumns(6, 3);
Autosizes columns F, G, and H.
The corresponding autosizing method for multiple rows is autoResizeRows(startRow, numRows)
s.autoResizeRows(6, 3);
Autosizes rows 6, 7, and 8
There is no corresponding single-row autosizing method (yet?); to autosize a single row, specify 1 for the number of rows
s.autoResizeRows(6, 1);
Autosizes only row 6
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