hisamounaのブログ

アウトプットを習慣化するためのブログ

SpreadSheetでチェックリストを使う (golang)

サンプルコード

コード

事前にやること

SpreadSheetのリンクを知っている人全員が編集できるようにする。

SpreadSheetID,SheetIDを取得

  • https://docs.google.com/spreadsheets/d/${SpreadSheetID}/edit#gid=${SheetID}

実行

           Range: &sheets.GridRange{
                StartRowIndex:    int64(1),
                EndRowIndex:      int64(3),
                StartColumnIndex: int64(1),
                EndColumnIndex:   int64(3),
                SheetId:          int64(sheetID),
            },

範囲をindexで指定 ((1,1) - (3,3) = B2 - C3)

Start~はinclusive, End~はexclusiveなので注意

空のシートに対して実行

SPREAD_SHEET_ID=${SpreadSheetID} SHEET_ID=${SheetID} go run main.go

f:id:hisamouna:20210911150746p:plain

デフォルトではチェックが付いていない状態(FALSE)でチェックボックスが作られる。

チェックを付ける

C2にチェックを付ける

   err = client.Update(fmt.Sprintf("%s!C2", os.Getenv("SHEET_NAME")), [][]interface{}{
        {
            true,
        },
    })

f:id:hisamouna:20210911152249p:plain