예제 #1
0
def get_sheets(service: discovery.Resource, docid: str) -> List[Sheet]:
    "Get the sheet titles and ids of the given spreadsheet."
    resp = service.spreadsheets().get(spreadsheetId=docid).execute()
    return [
        Sheet(docid, sheet['properties']['sheetId'],
              sheet['properties']['title']) for sheet in resp['sheets']
    ]
예제 #2
0
def iter_sheet(service: discovery.Resource,
               sheet: Sheet) -> Generator[List[str], None, None]:
    "Iterate over the contents of a particular sheet."
    size = get_sheet_size(service, sheet)
    resp = service.spreadsheets().values().batchGet(
        spreadsheetId=sheet.docid,
        ranges=sheets_upload.sheet_range(size[0], size[1],
                                         sheet.name)).execute()
    for row in resp['valueRanges'][0]['values']:
        yield row
예제 #3
0
def get_sheet_size(service: discovery.Resource, sheet: Sheet):
    "Get the size of a spreadsheet."
    resp = service.spreadsheets().get(spreadsheetId=sheet.docid,
                                      ranges=sheet.name).execute()
    grid_props = resp['sheets'][0]['properties']['gridProperties']
    return (grid_props['rowCount'], grid_props['columnCount'])