【发布时间】:2021-12-09 18:03:01
【问题描述】:
在这个使用 Sheets API 的 Google 表格中,有什么简单的示例可以在请求期间从表格中检索或通过 PHP 显示排除列 B 和 C?
可以从$service 请求中排除 B 列和 C 列吗?
或者,是否可以在 foreach 循环中将 B 列和 C 列排除在显示之外?
使用 R1C1 表示法?还是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;
}
这是现在的输出:
Joe Null blah blah Smith 123 Dogpatch Lane Dog Town Alabama 34567
John Blah Jones 456 猫空心猫镇阿肯色州 12345
Joe Not blah Johns 99 Cow Hollow Cow Town 阿肯色州 12345
我可以排除 B 列和 C 列,以便得到:
乔·史密斯 123 Dogpatch Lane Dog Town 阿拉巴马州 34567
约翰·琼斯 456 猫空心猫镇阿肯色州 12345
Joe Johns 99 Cow Hollow Cow Town 阿肯色州 12345
【问题讨论】:
标签: php google-sheets google-sheets-api