sheets

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrGetSheetIdNotFound = fmt.Errorf("sheet not found")

Functions

This section is empty.

Types

type Option

type Option func(*option_)

func WithMajorDimension

func WithMajorDimension(md string) Option

func WithValueInputOption

func WithValueInputOption(viopt string) Option

type Service

type Service struct {
	*sheets.Service
}

func NewService

func NewService(ctx context.Context, client *http.Client) (*Service, error)

NewService is the wrapper function for sheets.NewService To use OAuth2 Client Authentication, give the client which was returned by oauth2 package.

func (Service) DeleteRows

func (s Service) DeleteRows(spreadsheetId string, sheetTitle string, startIndex int64, endIndex int64) error

DeleteRows delets rows from the sheet specified by `spreadsheetId` and `sheetTitle`. `startIndex` and `endIndex` are zero-based, and 0 means unbounded.

see also: - https://developers.google.com/sheets/api/samples/rowcolumn#delete_rows_or_columns - https://developers.google.com/sheets/api/reference/rest/v4/DimensionRange

func (Service) Get

func (s Service) Get(spreadsheetId string, range_ string, options ...Option) (*sheets.ValueRange, error)

Get gets values of the range in specified sheet.

func (Service) GetObj

func (s Service) GetObj(spreadsheetId string, range_ string, dst interface{}, options ...Option) error

GetObj gets values of the range in specified sheet and store them into dst. dst must be a pointer to a slice of the Object that have `column` tag. The 1st row of the range is used to map columns and fields of dst Object.

mapping example:

| A          | B   | C    | D       |
| ---------- | --- | ---- | ------- |

1 | imported | id | name | checked | 2 | 2021-08-15 | 123 | Foo | 1 | 3 | 2021-08-16 | 456 | Bar | 0 |

type Row struct {
    Imported string `column:"imported"`
    Id       string `column:"id"`
    Name     string `column:"name"`
    Checked  string `column:"checked"`
}

var rows []Row GetObj(sheetId, "sheet!A1:D3", &row)

row = [

{ "2021-08-15", "123", "Foo", "1" },
{ "2021-08-16", "456", "Bar", "0" },

]

func (Service) GetSheetId

func (s Service) GetSheetId(spreadsheetId string, title string) (int64, error)

GetSheetId gets a sheet id by its title from the spreadsheet specified by `spreadsheetId`. You can find these IDs in a Google Sheets URL:

https://docs.google.com/spreadsheets/d/<spreadsheetId>/edit#gid=<sheetId>

see also: https://developers.google.com/sheets/api/guides/concepts

func (Service) Update

func (s Service) Update(spreadsheetId string, range_ string, values [][]interface{}, options ...Option) error

Update updates given range (initial position?) in the specified sheet with values.

func (Service) UpdateSheet

func (s Service) UpdateSheet(spreadsheetId string, sheetTitle string, src interface{}, options ...Option) error

UpdateSheet updates the sheet by src object. src must be a Slice of the object that have `column` tag. see GetObj for value mapping spec.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL