GASでスプレッドシートの指定セルのテキストの回転設定を取得する方法

GASでスプレッドシートの指定セルのテキストの回転設定を取得する方法
くら
くら

GASでスプレッドシートの指定セルのテキストの回転設定を取得する方法を紹介します!

こんな人にむけた記事です。
  • GASを使って、スプレッドシートの指定セルのテキストの回転設定を取得したい人
スポンサーリンク

指定セルのテキストの回転設定を取得:getTextRotation()

指定セルのテキストの回転設定を取得します。

パラメータ

名前 タイプ 説明
なし なし なし

戻り値

TextRotationテキストの回転設定

説明

function myFunction() {
    const sheet = SpreadsheetApp.getActiveSheet();
    const ss = SpreadsheetApp.getActiveSpreadsheet();

    // テキストの回転方向を取得
    let range = ss.getSheetByName("サンプル").getRange("B2");
    console.log("B2は垂直方向か:" + range.getTextRotation().isVertical());
    console.log("B2の角度は:" + range.getTextRotation().getDegrees());

    range = ss.getSheetByName("サンプル").getRange("B3");
    console.log("B3は垂直方向か:" + range.getTextRotation().isVertical());
    console.log("B3の角度は:" + range.getTextRotation().getDegrees());

    range = ss.getSheetByName("サンプル").getRange("B4");
    console.log("B4は垂直方向か:" + range.getTextRotation().isVertical());
    console.log("B4の角度は:" + range.getTextRotation().getDegrees());

    range = ss.getSheetByName("サンプル").getRange("C2");
    console.log("C2は垂直方向か:" + range.getTextRotation().isVertical());
    console.log("C2の角度は:" + range.getTextRotation().getDegrees());

    range = ss.getSheetByName("サンプル").getRange("C3");
    console.log("C3は垂直方向か:" + range.getTextRotation().isVertical());
    console.log("C3の角度は:" + range.getTextRotation().getDegrees());

    range = ss.getSheetByName("サンプル").getRange("C4");
    console.log("C4は垂直方向か:" + range.getTextRotation().isVertical());
    console.log("C4の角度は:" + range.getTextRotation().getDegrees());
}

以下のセルに対して、回転方向を取得します。

gettextrotation_sample
sample

サンプルコードを実行すると、各セルのテキスト回転方向の角度を取得でき、垂直方向の場合は True が返ってくることが確認できました!

gettextrotation_log
log

公式ドキュメント:Range > getTextRotation()

まとめ

くら
くら

スプレッドシートの指定セルのテキストの回転設定を取得する方法でした!

  • 指定セルのテキストの回転設定を取得したい時に使います!

コメント

タイトルとURLをコピーしました