2

我已经尝试过教程中的示例应用程序,但是如何从我的 php 页面向现有电子表格文件添加一行?

我必须将什么传递给更新功能???

我想要完成的是在每次提交表单后插入一个包含一些数据的新行

4

2 回答 2

5

您正在查看错误的 api。您需要https://developers.google.com/google-apps/spreadsheets/上的电子表格 api ,而不是 Drive api

于 2012-10-20T16:09:37.773 回答
1
$client = new \Google_Client();
$client->setApplicationName('GoogleSheets');
$client->setScopes([\Google_Service_Sheets::SPREADSHEETS]);
$client->setAccessType('offline');
$client->setAuthConfig($_SERVER['DOCUMENT_ROOT'] . '/credentials.json');

$service = new Google_Service_Sheets($client);
/**
* Write Row Google Sheet
*/
    
$spreadsheetID = '------';
$range = 'Sheet1';//Correct here for your sheet name
$values = [
    [1,2,3,4,5,6,7],
];
$body = new Google_Service_Sheets_ValueRange([
    'values' => $values
]);
$params = [
    'valueInputOption' => 'RAW',
];
$insert = [
    "insertDataOption"=> "INSERT_ROWS",
];
$result = $service->spreadsheets_values->append($spreadsheetID, $range, $body, $params, $insert);

于 2021-03-30T06:52:02.870 回答