Documentation ¶
Index ¶
- Variables
- type Option
- type Service
- func (s Service) DeleteRows(spreadsheetId string, sheetTitle string, startIndex int64, endIndex int64) error
- func (s Service) Get(spreadsheetId string, range_ string, options ...Option) (*sheets.ValueRange, error)
- func (s Service) GetObj(spreadsheetId string, range_ string, dst interface{}, options ...Option) error
- func (s Service) GetSheetId(spreadsheetId string, title string) (int64, error)
- func (s Service) Update(spreadsheetId string, range_ string, values [][]interface{}, options ...Option) error
- func (s Service) UpdateSheet(spreadsheetId string, sheetTitle string, src interface{}, options ...Option) error
Constants ¶
This section is empty.
Variables ¶
var ErrGetSheetIdNotFound = fmt.Errorf("sheet not found")
Functions ¶
This section is empty.
Types ¶
type Service ¶
type Service struct {
*sheets.Service
}
func NewService ¶
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 ¶
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