2017-06-18 42 views
1

如何通過Google Apps腳本一次更改多行的高度?如何一次更改多行的高度?

嘗試:

function resizeHeight() { 

  var s = SpreadsheetApp, 
      ui = s.getUi(), 
      sh = s.getActiveSheet(), 
     curntRow = s.getActiveRange().getRow(), 
     rowsMany = s.getActiveRange().getNumRows(), 
     autoRangeRows = s.getActiveRange().getA1Notation().replace(/[a-z]/gi,""), 
      getVal = ui.prompt('⿱⇕', 'Change the height of row❓   Cancel. Back to default❗  (21)', ui.ButtonSet.OK_CANCEL), 
      Btn = getVal.getSelectedButton(), Txt = getVal.getResponseText(); 

    for (var i=curntRow; i<=rowsMany+1; i++) { 
     if (Btn == 'OK') { 
     if (autoRangeRows.search(":") == -1) {sh.setRowHeight(curntRow, Txt);} 
     else {sh.setRowHeight(i, Txt);} 
     } 
     if (Btn == 'CANCEL') { 
     if (autoRangeRows.search(":") == -1) {sh.setRowHeight(curntRow, 21);} 
     else {sh.setRowHeight(i, 21);} 
     } 
    } 
} 

問題:

劇本不是很有效,他們只是對所有行可以實現部分或幾行,但不起作用。

+0

似乎對我來說過於複雜。 – Cooper

回答

1

此功能的工作原理:您只需選取一個活動範圍來選擇要更改高度的行,然後在提示中以像素爲單位給它一個高度。

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) 
    } 
}