https://github.com/takuoki/gsheets
A golang wrapper package for "golang.org/x/oauth2" and "google.golang.org/api/sheets/v4"
https://github.com/takuoki/gsheets
go golang google-sheets google-spreadsheet spreadsheet
Last synced: 5 months ago
JSON representation
A golang wrapper package for "golang.org/x/oauth2" and "google.golang.org/api/sheets/v4"
- Host: GitHub
- URL: https://github.com/takuoki/gsheets
- Owner: takuoki
- License: mit
- Created: 2019-03-29T04:23:47.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-05-06T15:03:53.000Z (almost 4 years ago)
- Last Synced: 2024-06-21T14:07:54.154Z (10 months ago)
- Topics: go, golang, google-sheets, google-spreadsheet, spreadsheet
- Language: Go
- Size: 25.4 KB
- Stars: 9
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-golang-repositories - gsheets
README
# gsheets
[](https://circleci.com/gh/takuoki/gsheets/tree/master)
[](https://codecov.io/gh/takuoki/gsheets)
[](https://godoc.org/github.com/takuoki/gsheets)
[](LICENSE)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
```bash
go get github.com/takuoki/gsheets
```## Requirement
This package uses Google OAuth2.0. So before executing tool, you have to prepare credentials.json.
See [Go Quickstart](https://developers.google.com/sheets/api/quickstart/go), or [Blog (Japanese)](https://medium.com/veltra-engineering/how-to-use-google-sheets-api-with-golang-9e50ee9e0abc) 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.```go
ctx := gsheets.WithCache(ctx)
```### Create New Client
```go
client, err := gsheets.New(ctx, `{"credentials": "json"}`, `{"token": "json"}`)
``````go
client, err := gsheets.NewForCLI(ctx, "credentials.json")
```If you are updating sheets, create a client with `ClientWritable` option.
```go
client, err := gsheets.New(ctx, `{"credentials": "json"}`, `{"token": "json"}`, gsheets.ClientWritable())
```### Get Sheet Information
```go
func (*Client) GetTitle(ctx context.Context, spreadsheetID string) (string, error)
``````go
func (*Client) GetSheetNames(ctx context.Context, spreadsheetID string) ([]string, error)
``````go
func (*Client) GetSheet(ctx context.Context, spreadsheetID, sheetName string) (Sheet, error)
```### Update Sheet Values
```go
func (c *Client) Update(ctx context.Context, spreadsheetID, sheetName string, rowNo int, values []interface{}) error
``````go
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.
```go
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))
}
```