'Google Sheets Script - Set a fixed height to rows (range as int)
I am unsuccessfully trying to reset my row heights on a regular basis to a certain value:
function clearGuestlist() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var first = ss.getSheetByName("FormsGuestlist");
var drucksheet = ss.getSheetByName("Druck");
var tabletsheet = ss.getSheetByName("Tablet");
var druckrange = drucksheet.getRange('Druck!1:200');
var tabletrange = tabletsheet.getRange('Tablet!1:200');
first.clearContents();
drucksheet.autoResizeRows(1, 200);
tabletsheet.autoResizeRows(1, 200);
drucksheet.setRowHeight(druckrange, 31);
tabletsheet.setRowHeight(tabletrange, 31);
}
The autoResizeRows unfortunately doesn't work in my case so I would like to use the setRowHeight, but it wouldn't accept my range as it expects an int.
Any idea how I can tell it to resize all my rows?
Thanks in advance
Solution 1:[1]
The Range class has a getRow() method that you can use to retrieve the row position as an integer.
You can call this on the druckrange and tabletrange objects to get the position and then use setRowHeights() to set the height for your selected number of rows. Note that you have to use setRowHeights() instead of setRowHeight() because you have to plug in the start row and number of rows, like in autoResizeRows(), whereas setRowHeight() just takes the position of a single row.
Your code should look something like this:
function clearGuestlist() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var first = ss.getSheetByName("FormsGuestlist");
var drucksheet = ss.getSheetByName("Druck");
var tabletsheet = ss.getSheetByName("Tablet");
var druckrange = drucksheet.getRange('Druck!1:200');
var tabletrange = tabletsheet.getRange('Tablet!1:200');
first.clearContents();
drucksheet.setRowHeights(druckrange.getRow(), 200, 31); //gets the row position of druckrange as an int, then sets height to 31 pixels for 200 rows
tabletsheet.setRowHeights(tabletrange.getRow(), 200, 31); //same as above for tabletrange
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Daniel |
