php - 如果使用 PHP 找到唯一 ID,则更新 Google 表格中的四列
问题描述
我有两个连续的 PHP 表格,表格一:应由团队成员填写,存储在带有自动生成的应用程序 ID 的谷歌表格中。表格二:应由团队负责人填写,与成员回复相关联地存储在上述相同的 google 表格中(如果负责人输入正确的申请 ID)。
Form One 运行良好!但是,使用Application ID关联Form 2响应并在同一行提交响应是我一直试图解决一个多星期但没有成功的技巧!
function submitApplication($responseId, $satisfaction, $attendance,
$communications, $commitment, $comments)
{
$indices = [
'responseId' => 1
];
$client = new \Google_Client();
$client->setApplicationName('Google Sheets and php');
$client->setScopes([\Google_Service_Sheets::SPREADSHEETS]);
$client->setAccessType('offline');
// $credentials_file = __DIR__ . "***";
//connection to destination DB
$credentials_file = __DIR__ . "***";
$spreadsheetId = '***';
$range = "Form Responses";
$client->setAuthConfig($credentials_file);
$service = new \Google_Service_Sheets($client);
$response = $service->spreadsheets_values->get($spreadsheetId, $range);
$values = $response->getValues();
foreach($values as $row){
if (empty($row))
continue;
//for ($i=0; $i<$valuesLength; $i++){
if($responseId === $row[$indices['responseId']]) {
print_r($row);
$valueRange = new Google_Service_Sheets_ValueRange();
$options = array('valueInputOption' => 'RAW');
$values = [[
$satisfaction
, $attendance
, $communications
, $commitment
, $comments
]];
$body = new Google_Service_Sheets_ValueRange(['values' => $values]);
$result = $service->spreadsheets_values->append($spreadsheetId, 'AB:AF', $body, $options);
print($result->updatedRange. PHP_EOL);
}
}
}
解决方案
推荐阅读
- git - 有人在 M1 CPU Mac 上成功运行 git-svn 吗?
- python - 如何在 python 中使用 pyopenssl 模块将证书链转储到 PEM 文件中
- python - What would be the python function that returns a list of elements that only appear once in a list
- r - R:在 0 x 0 矩阵上调用 apply 会导致调用 FUN(numeric(0))。为什么?这可以预防吗?
- c - 我在 C 中的函数出现问题,尝试使用较小的块方法计算回归斜率。谁能帮我找出我的错误?
- java - 每次在 Snake 游戏中增长时,都希望提高 Snake 的速度
- xamarin.forms - Xamarin 表单的 Wootric 集成
- python - 用相应属性的其他行的值有效地填充 df nan 字段?
- swift - 如何在 for 循环中排序(swift)
- c++ - 如何在 C++ 中读取以空格分隔且数据量不确定的文本文件?