我知道如何对Google Sheets API中的值和其他格式进行批量电子表格更新请求,但条件格式似乎有所不同。我的请求设置正确:
AddConditionalFormatRuleRequest formatRequest = new AddConditionalFormatRuleRequest
{
Rule = new ConditionalFormatRule
{
Ranges = new List<GridRange>
{
new GridRange
{
// omitted
}
},
BooleanRule = new BooleanRule
{
Condition = new BooleanCondition
{
// omitted
},
Format = new CellFormat
{
// omitted
}
},
},
};
formatRequests.Add(formatRequest);
问题是,您实际上如何执行此操作?问题出在这里:
BatchUpdateSpreadSheetRequest updateRequest = new BatchUpdateSpreadsheetRequest
{
Requests = formatRequests // this doesn't work
};
// resource is a SpreadsheetsResource object
SpreadsheetsResource.BatchUpdateRequest batchRequest = resource.BatchUpdate(updateRequest, spreadsheet.SpreadsheetId);
此部分不起作用,因为BatchUpdateSpreadSheetRequest.Requests
的类型为IList<Request>
,但AddConditionalFormatRuleRequest
不继承自Request
。它仅实现IDirectResponseActionSchema
(请参见source code第2254行),因此一个人实际上是如何执行这些请求的??
因此必须有其他一些对象/方法可以用来执行此操作,但是它在哪里?
提前感谢。
我知道如何对Google Sheets API中的值和其他格式进行批量电子表格更新请求,但条件格式似乎有所不同。我的请求设置正确:...
来自.NET背景,我真的很难理解如何使用Google API。 (对我而言)事情组织得很奇怪,.NET组件的文档看起来与MSDN完全不同,所以我觉得很困难。无论如何,我想通了。您不能单独使用AddConditionalFormatRuleRequest
类。您必须将其包装在常规Request
对象中。