LoginSignup
3
1

More than 1 year has passed since last update.

Google App Script で行数が多い行の高さを指定する

Last updated at Posted at 2021-06-07

リファレンスを見ると、setRowHeight(rowPosition, height) で出来そうなのですが、このメソッドは行数が指定した高さより多い場合には期待通りに動きませんでした。行数が多い場合、行の高さを「データに合わせる」設定に変更されてしまうようです。

setColumnWidth は文字数に関係なく幅が固定値で指定できるのに…。

他の方法を探していたら Stack Over flow に答えがありました。

Sheets API を有効にする

GAS の 左側メニュー < > のエディタをクリックして、サービスの + をクリックします。
サービスを追加から Google Sheets API を選択し、追加します。

スクリーンショット 2021-06-07 9.51.30.png

サンプルスクリプト

このサンプルは、2行目の高さを5pixelに変換します。

function myFunction() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getSheetByName("Sheet1");  // Please set the sheet name.

  const requests = {updateDimensionProperties: {
    properties: {pixelSize: 5},
    range: {sheetId: sheet.getSheetId(), startIndex: 1, endIndex: 2, dimension: "ROWS"},
    fields: "pixelSize"
  }};
  Sheets.Spreadsheets.batchUpdate({requests: requests}, ss.getId());
}

endIndex オプションを渡さない場合、全行の高さを変換します。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1