我正在使用api阅读Google表格,并按计划将值存储在数据库中。我想将记录的数据库ID写回表中,因此下次读取表时,我知道要更新而不是插入。我知道A1表示法,我只需要知道如何将值写回单元格即可。
我的阅读代码如下
putenv('GOOGLE_APPLICATION_CREDENTIALS=google_secret.json');
$client = new Google_Client;
$client->useApplicationDefaultCredentials();
$client->setApplicationName("Application Name");
$client->setScopes(['https://www.googleapis.com/auth/drive','https://spreadsheets.google.com/feeds']);
if ($client->isAccessTokenExpired()) {
$client->refreshTokenWithAssertion();
}
$accessToken = $client->fetchAccessTokenWithAssertion()["access_token"];
ServiceRequestFactory::setInstance(new DefaultServiceRequest($accessToken));
$spreadsheet = (new Google\Spreadsheet\SpreadsheetService)
->getSpreadsheetFeed()
->getByTitle("Test Doc ");
// Get the first worksheet (tab)
$worksheets = $spreadsheet->getWorksheetFeed()->getEntries();
$worksheet = $worksheets[0];
/***********************/
/* @var $worksheet Google\Spreadsheet\Worksheet */
/* @var $CellFeed Google\Spreadsheet\CellFeed */
$CellFeed = $worksheet->getCellFeed();
/* @var $E Google\Spreadsheet\CellEntry */
foreach ($CellFeed->getEntries() as $E)
{
//Iterate over each cell, import into database, and 'trying' to write back the id to the sheet
}