def get_first_row(client: discovery.Resource, spreadsheet_id: str, sheet_name: str) -> List[str]: spreadsheet = Spreadsheet.parse_obj( client.get(spreadsheetId=spreadsheet_id, includeGridData=True, ranges=f"{sheet_name}!1:1").execute()) # There is only one sheet since we are specifying the sheet in the requested ranges. returned_sheets = spreadsheet.sheets if len(returned_sheets) != 1: raise Exception( f"Unexpected return result: Sheet {sheet_name} was expected to contain data on exactly 1 sheet. " ) range_data = returned_sheets[0].data if len(range_data) != 1: raise Exception( f"Expected data for exactly one range for sheet {sheet_name}") all_row_data = range_data[0].rowData if len(all_row_data) != 1: raise Exception( f"Expected data for exactly one row for sheet {sheet_name}") first_row_data = all_row_data[0] return Helpers.get_formatted_row_values(first_row_data)
def get_sheets_in_spreadsheet(client: discovery.Resource, spreadsheet_id: str): spreadsheet_metadata = Spreadsheet.parse_obj( client.get(spreadsheetId=spreadsheet_id, includeGridData=False).execute()) return [ sheet.properties.title for sheet in spreadsheet_metadata.sheets ]