Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using batch_get for multiple pages such as spreadsheets.values.batchGet supports #1098

Open
fredericomattos opened this issue Aug 1, 2022 · 2 comments
Assignees
Labels
Feature Request Need investigation This issue needs to be tested or investigated

Comments

@fredericomattos
Copy link

I tried using batch_get to collect values in a single call:

sheet = client.open_by_key('XXXXXXXXXXXXXXXXXXXXXXXX')
print(sheet.batch_get(["'Page 1'!A1:A5","'Page 2'!A1:A5"]))

But I realized that it only accepts by setting the desired page after open_by_key, like open_by_key('...').worksheet('...').
That way are limited to using it on a single page.

I would like to request an "update" to this option that gives us the freedom to work with multiple pages in a single call, as is possible through the API (https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchGet):

image

image

{
  "spreadsheetId": "XXXXXXXXXXXXXXXXXXXXXXXX",
  "valueRanges": [
    {
      "range": "'Page 1'!A1:A5",
      "majorDimension": "ROWS",
      "values": [
        [
          "id"
        ],
        [
          "1"
        ],
        [
          "2"
        ],
        [
          "3"
        ],
        [
          "4"
        ]
      ]
    },
    {
      "range": "'Page 2'!A1:A5",
      "majorDimension": "ROWS",
      "values": [
        [
          "id"
        ],
        [
          "1"
        ],
        [
          "2"
        ],
        [
          "3"
        ],
        [
          "4"
        ]
      ]
    }
  ]
}
@lavigne958
Copy link
Collaborator

Hi this is an interesting request, in your case you try to use the method batch_get from a Worksheet object, so this is expected to only work with ranges in that sheet because you only need to provide the range, the method will handle the sheet name etc for you.

If you with to pull more ranges, from different worksheets, you can (for now) build your request manually and use the method Spreadsheet.values_batch_get which belong to a Spreadsheet instance and is not linked to any worksheet.

I can check if we can add a new method in the Spreadsheet class that can accept multiple ranges, but the spreadsheet class is not intended to provide such access, so some proper design is required, meaning I don't think I can plan that for the next release.

@lavigne958 lavigne958 added Feature Request Need investigation This issue needs to be tested or investigated labels Aug 4, 2022
@lavigne958 lavigne958 self-assigned this Aug 4, 2022
@fredericomattos
Copy link
Author

@lavigne958 looking further into the case, I think my view of expanding batch_get to multiple pages will be wrong indeed.

As values_batch_get returns all data and not just the values in the cells, if there was an option that returns exactly the same as batch_get but multiple sheets it would be perfect.

Just so don't have use ['valueRanges'][0]['values'] and ['valueRanges'][1]['values'] to get to cell values as is currently required in values_batch_get.

@alifeee alifeee added this to the 6.0.0 milestone Aug 8, 2023
@lavigne958 lavigne958 removed this from the 6.0.0 milestone Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Need investigation This issue needs to be tested or investigated
Projects
None yet
Development

No branches or pull requests

3 participants