I am trying to make a java program that auto create in-cell dropdown lists
in invidual cells.
My code (it runs without error but my sheet doesn't show the list):
Sheets service = getSheetsService();
SetDataValidationRequest setReq = new SetDataValidationRequest();
GridRange mRange = new GridRange();
mRange.setSheetId(sheet.getProperties().getSheetId());
mRange.setStartColumnIndex(6);
mRange.setEndColumnIndex(6);
mRange.setStartRowIndex(2);
mRange.setEndRowIndex(1001);
//set range for request
setReq.setRange(mRange);
String[] items = {"teen","18-24","25-34","35++"};
BooleanCondition bc = new BooleanCondition();
bc.setType("ONE_OF_LIST");
List<ConditionValue> listItem = new ArrayList<>();
for (String item : items) {
listItem.add(new ConditionValue().setUserEnteredValue(item));
}
bc.setValues(listItem);
//set rule
setReq.setRule(new DataValidationRule().setCondition(bc).setShowCustomUi
(true).setStrict(true));
Request rqDataValidation = new Request();
rqDataValidation.setSetDataValidation(setReq);
List<Request> rqList = new ArrayList<>();
rqList.add(rqDataValidation);
batchUpdate.setRequests(rqList);
System.out.println(batchUpdate.toString());
service.spreadsheets().batchUpdate(spreadsheetId,batchUpdate).execute();
And :
System.out.println(batchUpdate.toString());
print the json string of request:
{
requests = [{
setDataValidation = {
range = {
endColumnIndex = 6,
endRowIndex = 1001,
sheetId = *mySheetID*, //it is an int in real
startColumnIndex = 6,
startRowIndex = 2
},
rule = {
condition = {
type = ONE_OF_LIST,
values = [{
userEnteredValue = teen
}, {
userEnteredValue = 18 - 24
}, {
userEnteredValue = 25 - 34
}, {
userEnteredValue = 35++
}]
},
showCustomUi = true,
strict = true
}
}
}]
}
I tried set ProtectedRange and it works perfectly, but can't make the
dropdown list works. Google Sheets API document is poor.
--
You received this message because you are subscribed to the Google Groups
"Google Spreadsheets API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.