M
M
Mikhail Lebedinsky2021-04-10 22:58:15
Google
Mikhail Lebedinsky, 2021-04-10 22:58:15

Why are empty values ​​not being read when trying to read a GoogleSheets row?

import httplib2
import apiclient.discovery
from oauth2client.service_account import ServiceAccountCredentials
from pprint import pprint


def read_google_sheets(r):
    values = service.spreadsheets().values().get(
        spreadsheetId=spreadsheet_id,
        range=r,
        majorDimension='ROWS'
    ).execute()
    return values


CREDENTIALS_FILE = 'Project-99f7721baf37.json'
spreadsheet_id = '1walrfWQ65rxYF7dArX1HNOYYx9ROMo18jnK9NPAAAAA'

credentials = ServiceAccountCredentials.from_json_keyfile_name(
    CREDENTIALS_FILE,
    ['https://www.googleapis.com/auth/spreadsheets',
     'https://www.googleapis.com/auth/drive'])
httpAuth = credentials.authorize(httplib2.Http())
service = apiclient.discovery.build('sheets', 'v4', http = httpAuth)

pprint(read_google_sheets('A1:D1'))


This code works fine if the value in the last cell is not empty. But if the values ​​in the last cells are empty, it doesn't read them. How can I fix this without changing the table?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question