google: add LookupOrNewSheet

This commit is contained in:
c9s 2023-07-13 18:03:43 +08:00
parent 2de107c275
commit aa689b4c61
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -94,6 +94,19 @@ func (s *SpreadSheetService) LookupSheet(title string) (*sheets.Sheet, error) {
return nil, nil
}
func (s *SpreadSheetService) LookupOrNewSheet(title string) (*sheets.Sheet, error) {
sheet, err := s.LookupSheet(title)
if err != nil {
return nil, err
}
if sheet != nil {
return sheet, nil
}
return s.NewSheet(title)
}
func ReadSheetValuesRange(srv *sheets.Service, spreadsheetId, readRange string) (*sheets.ValueRange, error) {
log.Infof("ReadSheetValuesRange: %s", readRange)
resp, err := srv.Spreadsheets.Values.Get(spreadsheetId, readRange).Do()