.NET客户端中Google表格中的条件格式请求 [英] Conditional formatting requests in Google Sheets in .NET client

查看:78
本文介绍了.NET客户端中Google表格中的条件格式请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何对Google Sheets API中的值和其他格式进行批量电子表格更新请求,但条件格式似乎有所不同.我已经正确设置了请求:

I know how to do batch spreadsheet update requests for values and other formatting in the Google Sheets API, but conditional formatting seems to be different. I have the request set up properly:

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);

问题是,您如何实际执行此操作?问题出在这里:

The question is, how do you actually execute this? Here's the problem:

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 不能从请求.它仅实现 IDirectResponseActionSchema (请参见

This part doesn't work because BatchUpdateSpreadSheetRequest.Requests is of type IList<Request>, but AddConditionalFormatRuleRequest doesn't inherit from Request. It only implements IDirectResponseActionSchema (see source code line 2254), so how does one actually execute these requests??

因此必须有其他一些对象/方法可以用来执行此操作,但是它在哪里?

So there must be some other object/method that I'm supposed to use to do this, but where is it?

谢谢.

推荐答案

从.NET背景开始,我真的很难理解如何使用Google API.(对我而言)事情组织得很奇怪,.NET组件的文档看起来与MSDN完全不同,所以我觉得很困难.无论如何,我想通了.您不能单独使用 AddConditionalFormatRuleRequest 类.您必须将其包装在常规的 Request 对象中.

Coming from a .NET background, I really have a hard time wrapping my head around how to use the Google API. Things are just organized strangely (to me) and the documentation for the .NET components looks nothing like MSDN, so I just find it difficult. Anyway, I figured it out. You don't use the AddConditionalFormatRuleRequest class by itself. You have to wrap it in a regular Request object.

Request formatRequest = new Request
{
    AddConditionalFormatRule = new AddConditionalFormatRuleRequest
    {
        // etc
    }
};

这篇关于.NET客户端中Google表格中的条件格式请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆