我知道如何在 Google 表格 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
(参见源代码第 2254 行(,那么如何实际执行这些请求呢?
所以必须有一些其他的对象/方法,我应该使用它来做到这一点,但它在哪里?
提前谢谢。
来自.NET背景,我真的很难理解如何使用Google API。事情组织得很奇怪(对我来说(,.NET 组件的文档看起来一点也不像 MSDN,所以我只是觉得很困难。无论如何,我想通了。您不单独使用AddConditionalFormatRuleRequest
类。您必须将其包装在常规Request
对象中。
Request formatRequest = new Request
{
AddConditionalFormatRule = new AddConditionalFormatRuleRequest
{
// etc
}
};