Search code examples
c#google-sheets-api

Google Sheet api v4 dynamic sheet range


I am trying to access a sheet to get data and copy it in a data table I'm using the google sheets api v4 but I found that I must add the range to the request params.

Although I can't know how many columns has data in that sheet but the user is the one who set the spreadsheet url, so it varies and I can't find the specific range to add to the request.

So how can I find the range with contains all the data of that spreadsheet (knowing that all the spreadsheets the use can choose has only one sheet).


Solution

  • Answer:

    Unfortunately, there is no way of retrieving the data range of a sheet using the Google Sheets API.

    Workarounds:

    Google Apps Script has a .getDataRange() method of the Sheet class, which returns in A1 notation the range in which data is present in a Sheet. There is a workaround here which incorporates this method, though I am unsure if it is suitable for your use case.

    Feature Request:

    You can however let Google know that this is a feature that is important for the Sheets API and that you would like to request they implement it. Google's Issue Tracker is a place for developers to report issues and make feature requests for their development services. The page to file a Feature Request for the Google Sheets API is here.

    References: