Я пытаюсь обновить Google Sheet, используя функцию API листов batchUpdate. Я хочу добавить проверку данных (раскрывающиеся списки) для определенных столбцов на моем листе. Я отправляю список запросов, где каждый запрос имеет параметры, необходимые для каждого раскрывающегося списка. Однако когда я добавляю запросы в список, условия во всех ранее добавленных запросах заменяются новыми условиями.
Мой метод следующий:
public BatchUpdateSpreadsheetResponse setDropdownForPriceTest(String spreadsheetId) throws IOException, GeneralSecurityException {
Sheets service = GoogleDriveConnection.getSheetsService();
List<Request> requests = new ArrayList<>();
List<ConditionValue> conditionValueList = new ArrayList<>();
BooleanCondition booleanCondition;
DataValidationRule dataValidationRule;
GridRange range;
conditionValueList.clear();
String[] tripType = PriceBatchTestCase.TRIPTYPE;
for (String str: tripType) {
conditionValueList.add(new ConditionValue().setUserEnteredValue(str));
}
booleanCondition = new BooleanCondition().setType("ONE_OF_LIST").setValues(conditionValueList);
dataValidationRule = new DataValidationRule().setCondition(booleanCondition).setShowCustomUi(true).setStrict(true);
range = new GridRange().setSheetId(0).setStartRowIndex(1).setStartColumnIndex(1).setEndColumnIndex(2);
requests.add(new Request().setSetDataValidation(new SetDataValidationRequest().setRule(dataValidationRule).setRange(range)));
conditionValueList.clear();
String[] policyType = policyPackageService.getArrayPolicyPackageCode();
for (String str: policyType) {
conditionValueList.add(new ConditionValue().setUserEnteredValue(str));
}
booleanCondition = new BooleanCondition().setType("ONE_OF_LIST").setValues(conditionValueList);
dataValidationRule = new DataValidationRule().setCondition(booleanCondition).setShowCustomUi(true).setStrict(true);
range = new GridRange().setSheetId(0).setStartRowIndex(1).setStartColumnIndex(2).setEndColumnIndex(3);
requests.add(new Request().setSetDataValidation(new SetDataValidationRequest().setRule(dataValidationRule).setRange(range)));
conditionValueList.clear();
String[] area = PriceBatchTestCase.AREA;
for (String str: area) {
conditionValueList.add(new ConditionValue().setUserEnteredValue(str));
}
booleanCondition = new BooleanCondition().setType("ONE_OF_LIST").setValues(conditionValueList);
dataValidationRule = new DataValidationRule().setCondition(booleanCondition).setShowCustomUi(true).setStrict(true);
range = new GridRange().setSheetId(0).setStartRowIndex(1).setStartColumnIndex(15).setEndColumnIndex(16);
requests.add(new Request().setSetDataValidation(new SetDataValidationRequest().setRule(dataValidationRule).setRange(range)));
BatchUpdateSpreadsheetRequest body = new BatchUpdateSpreadsheetRequest().setRequests(requests);
BatchUpdateSpreadsheetResponse response = service.spreadsheets().batchUpdate(spreadsheetId, body).execute();
return response;
}
Вот как должен выглядеть список запросов (преобразованный в JSON) перед выполнением:
[
{
"setDataValidation": {
"range": {
"endColumnIndex": 2,
"sheetId": 0,
"startColumnIndex": 1,
"startRowIndex": 1
},
"rule": {
"condition": {
"type": "ONE_OF_LIST",
"values": [
{
"userEnteredValue": "SINGLE_TRIP"
},
{
"userEnteredValue": "ANNUAL_MULTI_TRIP"
}
]
},
"showCustomUi": true,
"strict": true
}
}
},
{
"setDataValidation": {
"range": {
"endColumnIndex": 3,
"sheetId": 0,
"startColumnIndex": 2,
"startRowIndex": 1
},
"rule": {
"condition": {
"type": "ONE_OF_LIST",
"values": [
{
"userEnteredValue": "ESSENTIALS"
},
{
"userEnteredValue": "CLASSIC"
},
{
"userEnteredValue": "DELUXE"
}
]
},
"showCustomUi": true,
"strict": true
}
}
},
{
"setDataValidation": {
"range": {
"endColumnIndex": 16,
"sheetId": 0,
"startColumnIndex": 15,
"startRowIndex": 1
},
"rule": {
"condition": {
"type": "ONE_OF_LIST",
"values": [
{
"userEnteredValue": "EUROPE_LR"
},
{
"userEnteredValue": "EUROPE_HR"
},
{
"userEnteredValue": "WORLD_HR"
},
{
"userEnteredValue": "WORLD_LR"
}
]
},
"showCustomUi": true,
"strict": true
}
}
}
]
Даже если отдельные запросы составлены правильно, фактический список запросов выглядит следующим образом:
[
{
"setDataValidation": {
"range": {
"endColumnIndex": 2,
"sheetId": 0,
"startColumnIndex": 1,
"startRowIndex": 1
},
"rule": {
"condition": {
"type": "ONE_OF_LIST",
"values": [
{
"userEnteredValue": "EUROPE_LR"
},
{
"userEnteredValue": "EUROPE_HR"
},
{
"userEnteredValue": "WORLD_HR"
},
{
"userEnteredValue": "WORLD_LR"
}
]
},
"showCustomUi": true,
"strict": true
}
}
},
{
"setDataValidation": {
"range": {
"endColumnIndex": 3,
"sheetId": 0,
"startColumnIndex": 2,
"startRowIndex": 1
},
"rule": {
"condition": {
"type": "ONE_OF_LIST",
"values": [
{
"userEnteredValue": "EUROPE_LR"
},
{
"userEnteredValue": "EUROPE_HR"
},
{
"userEnteredValue": "WORLD_HR"
},
{
"userEnteredValue": "WORLD_LR"
}
]
},
"showCustomUi": true,
"strict": true
}
}
},
{
"setDataValidation": {
"range": {
"endColumnIndex": 16,
"sheetId": 0,
"startColumnIndex": 15,
"startRowIndex": 1
},
"rule": {
"condition": {
"type": "ONE_OF_LIST",
"values": [
{
"userEnteredValue": "EUROPE_LR"
},
{
"userEnteredValue": "EUROPE_HR"
},
{
"userEnteredValue": "WORLD_HR"
},
{
"userEnteredValue": "WORLD_LR"
}
]
},
"showCustomUi": true,
"strict": true
}
}
}
]
Так что все три раскрывающихся списка имеют одинаковые значения. Почему это происходит?