mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-27 17:25:16 +00:00
google/sheets: add GetFirstColumn method
This commit is contained in:
parent
aa689b4c61
commit
eb9b3563da
|
@ -79,6 +79,7 @@ func (s *SpreadSheetService) NewSheet(title string) (*sheets.Sheet, error) {
|
||||||
return s.LookupSheet(title)
|
return s.LookupSheet(title)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LookupSheet looks up if there is a sheet matches the given title
|
||||||
func (s *SpreadSheetService) LookupSheet(title string) (*sheets.Sheet, error) {
|
func (s *SpreadSheetService) LookupSheet(title string) (*sheets.Sheet, error) {
|
||||||
spreadsheet, err := s.Get(false)
|
spreadsheet, err := s.Get(false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -94,6 +95,8 @@ func (s *SpreadSheetService) LookupSheet(title string) (*sheets.Sheet, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LookupSheet looks up if there is a sheet matches the given title
|
||||||
|
// And if there is no such a sheet, a sheet with that given title will be created.
|
||||||
func (s *SpreadSheetService) LookupOrNewSheet(title string) (*sheets.Sheet, error) {
|
func (s *SpreadSheetService) LookupOrNewSheet(title string) (*sheets.Sheet, error) {
|
||||||
sheet, err := s.LookupSheet(title)
|
sheet, err := s.LookupSheet(title)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -107,6 +110,17 @@ func (s *SpreadSheetService) LookupOrNewSheet(title string) (*sheets.Sheet, erro
|
||||||
return s.NewSheet(title)
|
return s.NewSheet(title)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SpreadSheetService) GetFirstColumn(sheet *sheets.Sheet) ([][]interface{}, error) {
|
||||||
|
title := sheet.Properties.Title
|
||||||
|
readRange := title + "!A1:A"
|
||||||
|
resp, err := ReadSheetValuesRange(s.service, s.SpreadsheetID, readRange)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp.Values, nil
|
||||||
|
}
|
||||||
|
|
||||||
func ReadSheetValuesRange(srv *sheets.Service, spreadsheetId, readRange string) (*sheets.ValueRange, error) {
|
func ReadSheetValuesRange(srv *sheets.Service, spreadsheetId, readRange string) (*sheets.ValueRange, error) {
|
||||||
log.Infof("ReadSheetValuesRange: %s", readRange)
|
log.Infof("ReadSheetValuesRange: %s", readRange)
|
||||||
resp, err := srv.Spreadsheets.Values.Get(spreadsheetId, readRange).Do()
|
resp, err := srv.Spreadsheets.Values.Get(spreadsheetId, readRange).Do()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user