我的目标是将空行设置为高1,并将填充行设置为合适的大小(自动调整大小),但是我找不到一种将这两行组合的方法。
这就是我当前正在使用的内容,但是它将空行设置为21而不是1:
function Higth() {
var s = SpreadsheetApp.getActive().getActiveSheet();
s.autoResizeRows(5, 31);
// 5 is the row in which the resizing starts and 31 is the amount of rows this is done
}
我希望有人知道这样做的方法。
约拿
答案 0 :(得分:1)
鉴于有效范围,我建议您使用this SO post中的实现:
function changeRowHeight() { var ss=SpreadsheetApp.getActiveSpreadsheet(); var sht=ss.getActiveSheet() var rng=sht.getActiveRange(); var row=rng.getRow(); var numrows=rng.getNumRows(); var resp=SpreadsheetApp.getUi().prompt('Get Row Height', 'Enter Row Height in Pixels', SpreadsheetApp.getUi().ButtonSet.OK); var height = Number(resp.getResponseText()); for(var i=0;i<numrows;i++) { sht.setRowHeight(row + i, height) } }
然后,您可以插入if()
语句,以使用autoResizeRows
中提供的Apps Script documentation函数检查给定行是否被文本填充。应该是这样的:
设置从给定行位置开始的所有行的高度以适合 他们的内容。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Sets the first 15 rows to a height that fits their text. sheet.autoResizeRows(1, 15);