1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GASでスプレッドシートにスマートチップを表示させる

1
Posted at

業務上GASを使う上で、スプレッドシート上にスマートチップを埋め込む必要が出てきました。
しかし、ネット上を探しても「スマートチップを埋め込む方法はない」という声が多数で、なかばあきらめていたのですが...
Sheets APIを利用すれば出来るみたいです。

insert_chip.gs
const spread_sheet_id = "spread_sheet_id"
const row_index = 0
const column_index = 0
const url = "https://XXXXXXXXXXX"


function set_chip_on_spreadsheet(){
  var resource = get_update_request();
  Logger.log(JSON.stringify(resource));

  const responce = Sheets.Spreadsheets.batchUpdate( resource, spread_sheet_id )
  Logger.log(JSON.stringify(responce));
}

function get_update_request() {
  var requests = [
    {
      updateCells: {
        rows: [
          {
            values: [
              {
                userEnteredValue: { stringValue: "@" }, // stringValueには@を含める
                chipRuns: [
                  {
                    chip: {
                      richLinkProperties: {
                        uri: url
                      }
                    }
                  }
                ]
              }
            ]
          }
        ],
        fields: "userEnteredValue,chipRuns",
        range: {
          startRowIndex: row_index,
          startColumnIndex: column_index,
          endRowIndex: row_index + 1,
          endColumnIndex: column_index + 1
        }
      }
    }
  ];
  const resource = { requests }
  return resource;
}

とりあえずこれをコピペすればスマートチップの埋め込みが出来るはずです。
後は権限とかGoogle Sheets APIを追加したりとかありますが...GASでスマートチップを埋め込もうとするような変人には解説はいらないと思うので割愛します。

ドキュメントの底の底の方にしれっと書いてあったので皆気づいてないのではと思い、一応共有しました。
Cells.ChipRun
お役に立てたら幸いです。

1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?