I am confused about the new Google Sheets API v4. My question is: how can I set validation rules for specified column(s) in spreadsheet? There is no useful tutorial with description how to use appropriate methods.
Result should look like following sample:
That validation should be set before data upload (which works fine).
My current code:
$client = getClient();
$service = new Google_Service_Sheets($client);
$fileId = 'my-document-id';
$body = new Google_Service_Sheets_SetDataValidationRequest(array(
'setRange' => new Google_Service_Sheets_GridRange(
array(
'sheetId'=>'List1',
'startColumnIndex'=>'0',
'endColumnIndex'=>'1'
)
),
'setRule' => new Google_Service_Sheets_DataValidationRule(
array(
'setValues'=>array('YES','NO')
)
)
));
$sheetReq = new Google_Service_Sheets_Request($client);
$sheetReq->setSetDataValidation($body);
$batchUpdateRequest = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest(array(
'requests' => $sheetReq
));
$result = $service->spreadsheets->batchUpdate($fileId, $batchUpdateRequest);
The DataValidationRule object would look like the following:
You want to use
rule.condition.type
ONE_OF_LIST and then enter therule.condition.values
you want in the list.showCustomUi
will show the dropdownA full example using google apps script from the Sheets script editor:
Thank you @random-parts for help, it has brought me to the right track. If someone else will try to solve similar problem in PHP in feature, please find bellow fully working example: