It is necessary to get information from the Google table using apis v4 for c #. In their example, they have a simple request for a specific range of cells.

// Define request parameters. String spreadsheetId = "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms"; String range = "Class Data!A2:E"; SpreadsheetsResource.ValuesResource.GetRequest request = service.Spreadsheets.Values.Get(spreadsheetId, range); 

In the range line we pass our range. But the problem is that you need to get a combined range. For example: enter image description here

Does anyone have an example of this batchGet request for c #?

    1 answer 1

    It may be so (I will not give all the code, it is standard):

     // Define request parameters. const string spreadsheetId = "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms"; const string range1 = "Class Data!B2:B7"; const string range2 = "Class Data!D2:E7"; SpreadsheetsResource.ValuesResource.BatchGetRequest request = service.Spreadsheets.Values.BatchGet(spreadsheetId); request.Ranges = new Repeatable<string>(new[] { range1, range2 }); BatchGetValuesResponse response = request.Execute(); IList<IList<object>> values = response.ValueRanges.SelectMany(x => x.Values).ToList(); if (values != null && values.Count > 0) { Console.WriteLine("Name, Major"); foreach (var row in values) { if (row.Count > 1) Console.WriteLine("{0} {1}", row[0], row[1]); else Console.WriteLine("{0}", row[0]); } } else { Console.WriteLine("No data found."); } 

    Result for the table

    enter image description here

    Will be:

     Name, Major Female Male Female Female Male Male CA English SD Math NC English SD Art WI English MD Art 
    • Thanks for the working example, there are 2 nuances. By default, it receives the cells first line by line, and with a combined range, it works first from 1 and then from 2. Is there any parameter that the combined range is perceived as one? And let's say it was considered in this order (B2, D2, E2) then go to the next line (B3, D3, E3) This is a screenshot in the answer - John Smith
    • @JohnSmith, yes, you can use the Zip method from System.Linq for this - Anton Komyshan