A golang wrapper package for golang.org/x/oauth2 and google.golang.org/api/sheets/v4.
You can easily manipulate spreadsheets.
!!! Only for personal use !!!
go get github.com/takuoki/gsheetsThis package uses Google OAuth2.0. So before executing tool, you have to prepare credentials.json. See Go Quickstart, or Blog (Japanese) for the details.
If you want to use the cache, initialize the context. If you are updating sheets, you should not use Cache.
ctx := gsheets.WithCache(ctx)client, err := gsheets.New(ctx, `{"credentials": "json"}`, `{"token": "json"}`)client, err := gsheets.NewForCLI(ctx, "credentials.json")If you are updating sheets, create a client with ClientWritable option.
client, err := gsheets.New(ctx, `{"credentials": "json"}`, `{"token": "json"}`, gsheets.ClientWritable())func (*Client) GetTitle(ctx context.Context, spreadsheetID string) (string, error)func (*Client) GetSheetNames(ctx context.Context, spreadsheetID string) ([]string, error)func (*Client) GetSheet(ctx context.Context, spreadsheetID, sheetName string) (Sheet, error)func (c *Client) Update(ctx context.Context, spreadsheetID, sheetName string, rowNo int, values []interface{}) errorfunc (c *Client) BatchUpdate(ctx context.Context, spreadsheetID string, updateValues ...UpdateValue) errorIf the index is out of range, Value method returns empty string.
s, err := client.GetSheet(ctx, "spreadsheetID", "sheetName")
if err != nil {
return err
}
fmt.Println(s.Value(row, clm))
for _, r := range s.Rows() {
fmt.Println(r.Value(clm))
}