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 ¶
- type Service
- func (svc *Service) Clear(id string, a1Ranges ...string) error
- func (svc *Service) DeleteSheet(id, title string) error
- func (svc *Service) GetRangeCSV(id, a1Range string) ([]byte, error)
- func (svc *Service) GetRangeFormatted(id string, a1Range string) ([][]string, error)
- func (svc *Service) GetRangeRaw(id string, a1Range string) ([][]interface{}, error)
- func (svc *Service) NewSheet(id, title string) error
- func (svc *Service) SheetFromTitle(id, title string) (*int64, error)
- func (svc *Service) Sort(id, name string, asc bool, column int64) error
- func (svc *Service) SpreadsheetsService() *sheets.SpreadsheetsService
- func (svc *Service) UpdateRangeCSV(id, a1Range string, values io.Reader) (*sheets.UpdateValuesResponse, error)
- func (svc *Service) UpdateRangeRaw(id, a1Range string, values [][]interface{}) (*sheets.UpdateValuesResponse, error)
- func (svc *Service) UpdateRangeStrings(id, a1Range string, values [][]string) (*sheets.UpdateValuesResponse, error)
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 ¶
NewServiceWithCtx creates and wraps a new Service with the provided context
func (*Service) Clear ¶
Clear clears the value of all 'a1Ranges' in the spreadsheet doc identified by 'id'.
func (*Service) DeleteSheet ¶
DeleteSheet deletes the sheet with 'title' from spreadsheet doc identified by 'id'
func (*Service) GetRangeCSV ¶
GetRangeCSV returns values in 'a1Range' from the spreadsheet doc identified by 'id' in csv format.
func (*Service) GetRangeFormatted ¶
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 ¶
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) SheetFromTitle ¶
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 ¶
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.)