【问题标题】:How do I set a basic filter in php using google sheets api?如何使用 google sheet api 在 php 中设置基本过滤器?
【发布时间】:2020-07-25 00:07:14
【问题描述】:

Google 为我提供了以下代码模板来设置基本过滤器。我只需要一个关于如何让我的 php 代码在我的 google 表格中创建条件过滤器的示例。有人可以帮忙吗?

// Filter sheet 
// TODO: Assign values to desired properties of `requestBody`:

$requestBody = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest();


$response = $service->spreadsheets->batchUpdate($spreadsheetId, $requestBody);

// TODO: Change code below to process the `response` object:
echo '<pre>', var_export($response, true), '</pre>', "\n";

?>

【问题讨论】:

  • 感谢@Paul T 的建议。下次我会这样做。
  • 这不是建议,只是编辑评论,但不用担心!

标签: php google-sheets-api


【解决方案1】:

解决方案

要使用Batch Update 发出过滤请求,您需要先设置your criteria as shown in the documentation,然后使用此条件构建your filter representation as also indicated in the documentation

以下是使用文档中的一些过滤条件的示例:

// Filter sheet 
// TODO: Assign values to desired properties of `requestBody`:

// Set desired criteria
$criteria->{'0'} = array(
    'condition' => array(
        'type' => 'DATE_BEFORE',
        'values' => array(
            'userEnteredValue' => '4/30/2016'
        )
    )
);

// Set requests array with the appropiate criteria
$requests = [
  new Google_Service_Sheets_Request( array(
        'requests' => array(
            'setBasicFilter' => array(
                'filter' => array(
                    'range' => [ // your desired range
                        'sheetId' => 0,
                        'startColumnIndex' => 0,
                        'endColumnIndex' => 0
                    ],
                'criteria' => $criteria
                )
            )
        )
    )
);

// Add the requests to the body
$requestBody = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest(array('requests' => $requests));


$response = $service->spreadsheets->batchUpdate($spreadsheetId, $requestBody);

// TODO: Change code below to process the `response` object:
echo '<pre>', var_export($response, true), '</pre>', "\n";

?>

我希望这对您有所帮助。让我知道您是否需要其他任何内容或者您是否不理解某些内容。 :)

【讨论】:

  • 感谢@MateoRandwolf。它几乎奏效了。我最后做了类似的事情。
  • 嗨!您能否解释/发布作为您自己问题的答案,您为解决您的问题做了哪些更改?这将帮助其他有类似问题的用户更轻松地找到答案。谢谢 ! :D
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多