In this Google Sheet using the Sheets API, what's a simple example of excluding columns B and C from either retrieval from the Sheet during the request, or display via PHP?
Can columns B and C be excluded from the $service
request?
Or, can columns B and C be excluded from display in the foreach loop?
Use R1C1 notation? Or majorDimension? https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values
// Usual suspects
require_once __DIR__ . '/vendor/autoload.php';
$googleAccountKeyFilePath = __DIR__ . '/service_key.json';
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $googleAccountKeyFilePath);
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope('https://www.googleapis.com/auth/spreadsheets');
$service = new Google_Service_Sheets($client);
$spreadsheetId = '';
$response = $service->spreadsheets->get($spreadsheetId);
$spreadsheetProperties = $response->getProperties();
//The $range where columns could be excluded?
$range = 'Sheet1!A2:I';
$response = $service->spreadsheets_values->get($spreadsheetId, $range);
$values = $response->getValues();
//The foreach loop where columns could be excluded?
foreach($values as $val) {
$valuespan = "<span>".implode('</span> <span>', $val)."</span>";
echo $valuespan;
}
This is the output right now:
Joe Null blah blah Smith 123 Dogpatch Lane Dog Town Alabama 34567
John Blah Jones 456 Cat Hollow Cat Town Arkansas 12345
Joe Not blah Johns 99 Cow Hollow Cow Town Arkansas 12345
Hoe can I exclude Columns B and C so I get:
Joe Smith 123 Dogpatch Lane Dog Town Alabama 34567
John Jones 456 Cat Hollow Cat Town Arkansas 12345
Joe Johns 99 Cow Hollow Cow Town Arkansas 12345