くら
GASでスプレッドシートの指定セルのリッチテキストを取得する方法を紹介します!
指定セルのリッチテキストを取得:getRichTextValue()
指定セルのリッチテキストを取得します。
パラメータ
名前 | タイプ | 説明 |
---|---|---|
なし | なし | なし |
戻り値
RichTextValue | リッチテキストの値 |
説明
function myFunction() {
const sheet = SpreadsheetApp.getActiveSheet();
const ss = SpreadsheetApp.getActiveSpreadsheet();
const range = ss.getSheetByName("サンプルA").getRange("A1");
const richText = range.getRichTextValue()
// セルの値
console.log("セルの値:" + richText.getText());
// hogeの文字サイズ
console.log("hogeの文字サイズ:" + richText.getTextStyle(1, 4).getFontSize());
// fugaの文字サイズ
console.log("fugaの文字サイズ:" + richText.getTextStyle(5, 8).getFontSize());
// hogeが太字かどうか
console.log("hogeが太字かどうか:" + richText.getTextStyle(1, 4).isBold());
// fugaが太字かどうか
console.log("fugaが太字かどうか:" + richText.getTextStyle(5, 8).isBold());
// hogeの文字色
console.log("hogeの文字色:" + richText.getTextStyle(1, 4).getForegroundColor());
// fugaの文字色
console.log("fugaの文字色:" + richText.getTextStyle(5, 8).getForegroundColor());
}
A1のリッチテキストについて、hogeとfugaのそれぞれの書式を取得してみます。
サンプルコードを実行すると、hogeとfugaの書式を取得することができました!
公式ドキュメント:Range > getRichTextValue()
まとめ
くら
スプレッドシートの指定セルのリッチテキストを取得する方法でした!
コメント