# README
gsheets
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 !!!
Installation
go get github.com/delve/gsheets
Requirement
This package uses Google OAuth2.0. So before executing tool, you have to prepare credentials.json. See Go Quickstart, or Blog (Japanese) for the details.
Usage
Create Cache
If you want to use the cache, initialize the context. If you are updating sheets, you should not use Cache.
ctx := gsheets.WithCache(ctx)
Create New Client
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())
Get Sheet Information
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)
Update Sheet Values
func (c *Client) Update(ctx context.Context, spreadsheetID, sheetName string, rowNo int, values []interface{}) error
func (c *Client) BatchUpdate(ctx context.Context, spreadsheetID string, updateValues ...UpdateValue) error
Manipulate Sheet Values
If 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))
}
# Functions
ClientWritable is an option to change client writable.
New returns a gsheets client.
TODO: Convert this to the way New() works with direct google clientoptions NewForCLI returns a gsheets client.
NewSheet returns a new sheet instance with argument values.
WithCache returns a context with gsheets cache.
# Structs
Client is a gsheets client.
Row is a row of google spreadsheets.
Sheet is a sheet of google spreadsheets.
UpdateValue is data structure for BatchUpdate method.
# Type aliases
Type and optionFunc are now only used in NewForCli, which i am not using atm ClientOption is an option function.