I'm following the documentation following the google-sheets-api documentation for php. I get everything to work, with the sheet example and with my own project sheet.
And they use a variable range (with the range in the spreadsheet) whereas later they make a foreach loop to show the values in a row. The row[integer] should give the correct column. And here is how it gets vague for me.
// Print columns A and E, which correspond to indices 0 and 4. Is the information given.
printf( "%s ", $row[0],$row[2], $row[4]);
This line of code should make the data visible of the columns and row. In the example I can make this work, showing a max of 3column with data.
I want to retrieve and show the complete data in the sheet.
And! I can't use the all function because the custom document has to many arguments to retrieve and is unusable.
Question: How do I calculate/retrieve the correct indices vs the columns A to F in a document.
Description of what I did in the code ****
// Get the API client and construct the service object.
$client = getClient();
$service = new Google_Service_Sheets($client);
// Prints the names and majors of students in a sample spreadsheet:
// https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit
// 1dbRAXK6EVbSIFWB5mKleh2ziutwavrRLvs07uoBPJbk ****custom sheet****
$spreadsheetId = '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms';
$range = 'Class Data!A1:C5';// *** ma1! and all sorts of combinations
$response = $service->spreadsheets_values->get($spreadsheetId, $range);
$values = $response->getValues();
if (empty($values)) {
print "No data found.
";
} else {
foreach ($values as $row) {
printf( "%s
", $row[0],$row[2], $row[4]); // ***** added row, deleted row, tried to add a foreach col loop. Tried to figure out what happens when I get 1 column and trying to add new columns. *****
}
}
I want to retrieve and show the complete data in the sheet.