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";
?>
发布于 2020-07-27 11:06:40
解决方案
为了使用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";
?>
我希望这对你有所帮助。如果你还需要什么,或者你不明白什么,请告诉我。:)
https://stackoverflow.com/questions/63082939
复制相似问题