Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何通过存储在其中的值来搜索Google工作表_Php_Google Api_Google Sheets Api - Fatal编程技术网

Php 如何通过存储在其中的值来搜索Google工作表

Php 如何通过存储在其中的值来搜索Google工作表,php,google-api,google-sheets-api,Php,Google Api,Google Sheets Api,我需要搜索存储在工作表中的特定值,并获取存储该值的整行或单元格的位置 注意:我的工作表包含10000多行数据,我需要更新一列。我不想从工作表中获取所有数据并进行更新,因为这会影响我网站的性能 请帮我找到解决办法 迟做总比不做强!? 我也有同样的问题,但我需要更改多个字段,我甚至查看了上面的链接,但在php中什么都没有。如果只需要更改一个或多个字段,下面的代码也可以使用。(谷歌翻译) 当您存储该值时,还要在其上设置一些开发人员元数据。然后可以按开发人员元数据进行筛选。我想这是我在这里被问到的问题的

我需要搜索存储在工作表中的特定值,并获取存储该值的整行或单元格的位置

注意:我的工作表包含10000多行数据,我需要更新一列。我不想从工作表中获取所有数据并进行更新,因为这会影响我网站的性能

请帮我找到解决办法

迟做总比不做强!? 我也有同样的问题,但我需要更改多个字段,我甚至查看了上面的链接,但在php中什么都没有。如果只需要更改一个或多个字段,下面的代码也可以使用。(谷歌翻译)


当您存储该值时,还要在其上设置一些开发人员元数据。然后可以按开发人员元数据进行筛选。我想这是我在这里被问到的问题的一部分:
<?php
     $myvalue = 'NEW VALUE';
    $values = [[$c_id,]];
    // make conn with credentials
    $client = new \Google_Client();
    $client->setApplicationName('Google Sheets with PHP');
    $client->setScopes([\Google_Service_Sheets::SPREADSHEETS]);
    $client->setAccessType('offline');
    $client->setAuthConfig(__DIR__ . '/cred.json');
    $service = new Google_Service_Sheets($client);
    $spreadsheetId = "your-id";

    // insert custom range to match with name of spreadsheet and range to search  
    $range = "COMPLETO!A2:A50000";
    $cell_id;
    $cell_range;
    $response = $service->spreadsheets_values->get($spreadsheetId, $range);
    $values_r = $response->getValues();           
    if (empty($values_r)) {
        print "None Found.\n";
    } else {
        print "Data found\n";
        $range_index = '1';
        foreach ($values_r as $row) {
            // Show the results in array 
            $range_index++;
            // Match com id do banco de dados
            if($row[0] === $c_id){
                echo "ID found\n";
                echo "$row[0]\n";
                echo "Cell ID A${range_index}\n";
                $cell_id = "A${range_index}";
                // in $cell_range set the effective range to change
               // $cell_range = "A${range_index}:CM${range_index}";
                break;
            }
        }
    }

    $body = new Google_Service_Sheets_ValueRange([
    'values' => $values
    ]);
    // try Update
     $append_sheet = $service->spreadsheets_values->update($spreadsheetId, $cell_range, $body,['valueInputOption' => 'RAW']);
    echo "Update Google Sheet\n";
    $conn = null;