c# - Google Sheets API .NET v4 为网格单元创建下拉列表
问题描述
我正在尝试在网格上创建一个下拉列表。我正在遵循此页面上的建议。但是,我无法为UserEnteredValue
. 我得到的带下划线的错误:
无法将类型“Google.Apis.Sheets.v4.Data.ConditionValue”隐式转换为“System.Collections.Generic.IList”。存在显式转换(您是否缺少演员表?)
public Request createDataValidationRequest(int sheetID, int startRow, int endRow, int startColumn, int endColumn)
{
var updateCellsRequest = new Request() {
SetDataValidation = new SetDataValidationRequest()
{
Range = new GridRange()
{
SheetId = sheetID,
StartRowIndex = startRow,
StartColumnIndex = startColumn,
EndRowIndex = endRow,
EndColumnIndex = endColumn
},
Rule = new DataValidationRule()
{
Condition = new BooleanCondition()
{
Type = "ONE_OF_LIST",
Values = new ConditionValue()
{
UserEnteredValue = "awer"
}
},
InputMessage = "Select an Option",
ShowCustomUi = true,
Strict = true
}
}
};
return updateCellsRequest;
}
解决方案
对于我的情况,我能够获得以下信息。
SpreadsheetsResource.GetRequest request = _sheetsService.Spreadsheets.Get(newTimeSheet.Id);
Spreadsheet spreadsheet = request.Execute();
SheetProperties timeSheetProperties = new SheetProperties();
for (int z = 0; z < spreadsheet.Sheets.Count; z++)
{
SheetProperties sheetProperties = spreadsheet.Sheets[z].Properties;
if (sheetProperties.Title == "3c TIME")
{
timeSheetProperties = sheetProperties;
break;
}
}
var updateCellsRequest = new Request()
{
SetDataValidation = new SetDataValidationRequest()
{
Range = new GridRange()
{
SheetId = timeSheetProperties.SheetId,
StartRowIndex = 2,
StartColumnIndex = 0,
EndColumnIndex = 1
},
Rule = new DataValidationRule()
{
Condition = new BooleanCondition()
{
//Type = "ONE_OF_RANGE",
Type = "ONE_OF_LIST",
Values = new List<ConditionValue>()
{
new ConditionValue()
{
UserEnteredValue = "YES",
},
new ConditionValue()
{
UserEnteredValue = "NO",
},
new ConditionValue()
{
UserEnteredValue = "MAYBE",
}
}
},
InputMessage = "Select an Option",
ShowCustomUi = true,
Strict = true
}
}
};
var requestBody = new Google.Apis.Sheets.v4.Data.BatchUpdateSpreadsheetRequest();
var requests = new List<Request>();
requests.Add(updateCellsRequest);
requestBody.Requests = requests;
var batchRequest = _sheetsService.Spreadsheets.BatchUpdate(requestBody, newTimeSheet.Id);
batchRequest.Execute();
推荐阅读
- microservices - 特定于域的协议是什么意思?
- python-3.x - Docker:将 LibXMLSec 设置/依赖项移动到可执行目录中
- sql - 从审计表中为每个用户 ID 选择旧价格
- javascript - 如何设置这个 javascript 按钮的样式?
- excel - 如何将2小时添加到excel的当前时间
- php - Codeigniter 模型返回空数据
- django - Django,如何在 Listview 上显示 2 个模型
- wxwidgets - 使用带有 wxWidgets 的 Github CI 管道
- r - 数据框:有条件地将特定值与其他列的所有值进行比较,并将结果向量存储在列表列中
- hive - Hive 有条件地选择列名