首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何使用google sheets api在php中设置基本过滤器?

如何使用google sheets api在php中设置基本过滤器?
EN

Stack Overflow用户
提问于 2020-07-25 00:07:14
回答 1查看 173关注 0票数 0

Google给了我下面的代码模板来设置一个基本的过滤器。我只需要一个例子,我可以让我的php代码创建一个条件过滤器在我的google工作表。有人能帮帮忙吗?

代码语言:javascript
运行
AI代码解释
复制
// 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";

?>
EN

回答 1

Stack Overflow用户

发布于 2020-07-27 11:06:40

解决方案

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

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

代码语言:javascript
运行
AI代码解释
复制
// 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";

?>

我希望这对你有所帮助。如果你还需要什么,或者你不明白什么,请告诉我。:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63082939

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档