我正在使用Python 3并且一直在尝试从列电子表格中检索值而不是行。我看过示例here that explains that majorDimension need to be changed to COLUMNS 但是,这段代码:
rangeName = 'sheet1!A2:D4?majorDimension=COLUMNS'
result = service.spreadsheets().values().get(
spreadsheetId=spreadsheetId, range=rangeName).execute()
values = result.get('values', [])
print (values)
返回
<HttpError 400 when requesting https://sheets.googleapis.com/v4/spreadsheets/143FCe6qayfm-g8-PvYr_rz5fF4Fjpg-ZZVWbF11xF6o/values/HCMasterX%21A2%3AD4%2CmajorDimension%3DCOLUMNS?alt=json returned "Unable to parse range: HCMasterX!A2:D4,majorDimension=COLUMNS">
同时,
rangeName = 'sheet1!A2:D4'
result = service.spreadsheets().values().get(
spreadsheetId=spreadsheetId, range=rangeName).execute()
values = result.get('values', [])
完美无缺,打印出正确的值。 我已经尝试将rangeName更改为许多其他变体,例如结束它 &#34;,majorDimensions = COLUMNS&#34;但他们都没有奏效。 非常感谢任何帮助/指导!
答案 0 :(得分:1)
我认为你只是将其作为参数传递给:
rangeName = 'sheet1!A2:D4'
result = service.spreadsheets().values().get(
spreadsheetId=spreadsheetId,
range=rangeName,
majorDimension='COLUMNS').execute()