gsheets

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

gsheets is a package which provides utilities for manipulating (get and update data, clear, sort) Google Sheets documents. This can be more simple than using Google's API for common tasks (especially for sending and receiving csv data to and from Sheets); for anything more complicated use Google's golang sdk directly: https://pkg.go.dev/google.golang.org/api@v0.50.0/sheets/v4

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service struct {
	Sep rune // record separator when [un]serializing csv
	// contains filtered or unexported fields
}

Service is a wrapper around both SpreadsheetsService and SpreadsheetsValuesService

func NewServiceWithCtx

func NewServiceWithCtx(ctx context.Context) (*Service, error)

NewServiceWithCtx creates and wraps a new Service with the provided context

func (*Service) Clear

func (svc *Service) Clear(id string, a1Ranges ...string) error

Clear clears the value of all 'a1Ranges' in the spreadsheet doc identified by 'id'.

func (*Service) DeleteSheet

func (svc *Service) DeleteSheet(id, title string) error

DeleteSheet deletes the sheet with 'title' from spreadsheet doc identified by 'id'

func (*Service) GetRangeCSV

func (svc *Service) GetRangeCSV(id, a1Range string) ([]byte, error)

GetRangeCSV returns values in 'a1Range' from the spreadsheet doc identified by 'id' in csv format.

func (*Service) GetRangeFormatted

func (svc *Service) GetRangeFormatted(id string, a1Range string) ([][]string, error)

GetRangeFormatted gets formatted values in 'a1Range' from the spreadsheet doc identified by 'id'. All values are returned as strings, formatted as they display in the spreadsheet document

func (*Service) GetRangeRaw

func (svc *Service) GetRangeRaw(id string, a1Range string) ([][]interface{}, error)

GetRangeRaw gets unformatted values in 'a1Range' from the spreadsheet doc identified by 'id'. You must type switch the resulting [][]interface{} (outer slice is rows, inner slice is value per column) A1 syntax: https://developers.google.com/sheets/api/guides/concepts

func (*Service) NewSheet

func (svc *Service) NewSheet(id, title string) error

NewSheet creates a new sheet on spreadsheet identified by 'id'

func (*Service) SheetFromTitle

func (svc *Service) SheetFromTitle(id, title string) (*int64, error)

SheetFromTitle returns the sheetID for the sheet with 'title' in the spreadsheet doc identified by 'id'. If no error is encountered and no matching sheet is found, both return values will be nil.

func (*Service) Sort

func (svc *Service) Sort(id, name string, asc bool, column int64) error

Sort sorts the sheet titled 'name' on the spreadsheet doc identified by 'id' by 'column'. If asc is true, sort ascending; otherwise sort descending Column is the column index rather than A1 notation (0=A, 1=B, ...)

func (*Service) SpreadsheetsService

func (svc *Service) SpreadsheetsService() *sheets.SpreadsheetsService

SpreadsheetsService returns a pointer to the wrapped SpreadsheetsService

func (*Service) UpdateRangeCSV

func (svc *Service) UpdateRangeCSV(id, a1Range string, values io.Reader) (*sheets.UpdateValuesResponse, error)

UpdateRangeCSV update values in 'a1Range' in the spreadsheet doc identified by 'id' to 'values'. 'values' is an io.Reader which supplies text in csv format. Values will be parsed by Google Sheets as if they were typed in by the user (so strings containing numerals may be converted to numbers, etc.)

func (*Service) UpdateRangeRaw

func (svc *Service) UpdateRangeRaw(id, a1Range string, values [][]interface{}) (*sheets.UpdateValuesResponse, error)

UpdateRangeRaw updates the values in 'a1Range' in the spreadsheet doc identified by 'id' to 'values'. Each value in 'values' must be a string, float, int, or bool and must fit within the dimensions of 'a1Range'.

func (*Service) UpdateRangeStrings

func (svc *Service) UpdateRangeStrings(id, a1Range string, values [][]string) (*sheets.UpdateValuesResponse, error)

UpdateRangeStrings update values in 'a1Range' in the spreadsheet doc identified by 'id' to 'values'. Values will be parsed by Google Sheets as if they were typed in by the user (so strings containing numerals may be converted to numbers, etc.)

Jump to

Keyboard shortcuts

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