【发布时间】:2019-07-15 22:59:27
【问题描述】:
目前我正在通过他们的 PHP 库使用 Google Sheets API 来构建动态电子表格。我在电子表格上设置了验证规则,专门用于创建要选择的状态下拉列表。
我已经更新了电子表格,将状态下拉列表放在不同的列中。但是,执行此操作后,为上一列设置的 DataValidationRule 似乎仍然存在。
在重新应用我想要的任何验证之前,我尝试创建一种方法来删除工作表中的所有验证,但它似乎不起作用。
https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#conditiontype
在设置条件类型时,我想将验证恢复为CONDITION_TYPE_UNSPECIFIED,但如果我这样做,API 只会返回一个错误。我尝试使用其他人,例如ONE_OF_LIST,但随后每个单元格都错误提示:
Invalid: Input must be an item on specified list
这是有道理的,考虑到没有生成列表(我也不想要一个)。
其余列可以是数字/日期/文本的任意组合,因此我想在再次应用验证之前简单地删除所有验证。
这是我当前的 clearValidation 代码:
public function clearSpreadsheetValidations($spreadsheetId) {
$client = $this->getClient();
$service = new Google_Service_Sheets($client);
$conditions = new Google_Service_Sheets_BooleanCondition();
$conditions->setType('CONDITION_TYPE_UNSPECIFIED');
$conditions->setValues(null);
$setRule= new Google_Service_Sheets_DataValidationRule();
$setRule->setCondition($conditions);
$setRule->setInputMessage(null);
$setRule->setShowCustomUi(false);
$valReq = new Google_Service_Sheets_SetDataValidationRequest();
$valReq->setRule($setRule);
$sheetReq = new Google_Service_Sheets_Request();
$sheetReq->setSetDataValidation($valReq);
$requestBody = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest();
$requestBody->setRequests($sheetReq);
$service->spreadsheets->batchUpdate($spreadsheetId, $requestBody);
}
如何调用工作表 API 以删除电子表格中所有以前设置的 DataValidationRules?
谢谢!
【问题讨论】:
标签: php google-sheets google-sheets-api