Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在C#中格式化Google Sheets API v4中的标题行?_C#_Google Sheets_Google Sheets Api_Google Api Dotnet Client - Fatal编程技术网

如何在C#中格式化Google Sheets API v4中的标题行?

如何在C#中格式化Google Sheets API v4中的标题行?,c#,google-sheets,google-sheets-api,google-api-dotnet-client,C#,Google Sheets,Google Sheets Api,Google Api Dotnet Client,我想要以下输出: 但我得到以下结果: 我遵循了关于这个问题的说明: 但此代码在工作表的所有行和列上都是粗体的 我怎样才能解决这个问题? 我的代码是: var userEnteredFormat = new CellFormat() { TextFormat = new TextFormat() { Bold = true, FontSize = 12 } }; BatchUpdateSpreadsheetRequest batchu

我想要以下输出:

但我得到以下结果:

我遵循了关于这个问题的说明:

但此代码在工作表的所有行和列上都是粗体的

我怎样才能解决这个问题? 我的代码是:

var userEnteredFormat = new CellFormat()
{
    TextFormat = new TextFormat()
    {
        Bold = true,
        FontSize = 12
    }
};

BatchUpdateSpreadsheetRequest batchupdateCell = new BatchUpdateSpreadsheetRequest();

//create the update request for cells from the first row
var updateCellsRequest = new Request()
{
    RepeatCell = new RepeatCellRequest()
    {
        Range = new GridRange()
        {
            SheetId = sheetId,
            StartColumnIndex = 0,
            StartRowIndex = 0,
            EndColumnIndex = 28,
            EndRowIndex = 1
        },
        Cell = new CellData()
        {
            UserEnteredFormat = userEnteredFormat
        },
        Fields = "UserEnteredFormat(TextFormat)"
    }
};

batchupdateCell.Requests = new List<Request>();
batchupdateCell.Requests.Add(updateCellsRequest);
SpreadsheetsResource.BatchUpdateRequest bur = service.Spreadsheets.BatchUpdate(batchupdateCell, SheetId);
BatchUpdateSpreadsheetResponse responseUpdate3 = bur.Execute();
var userEnteredFormat=new CellFormat()
{
TextFormat=新的TextFormat()
{
粗体=正确,
字体大小=12
}
};
BatchUpdateSpreadsheetRequest batchupdateCell=新的BatchUpdateSpreadsheetRequest();
//从第一行创建单元格的更新请求
var updateCellsRequest=新请求()
{
RepeatCell=新的RepeatCellRequest()
{
范围=新的GridRange()
{
SheetId=SheetId,
StartColumnIndex=0,
StartRowIndex=0,
EndColumnIndex=28,
EndRowIndex=1
},
单元=新单元数据()
{
UserEnteredFormat=UserEnteredFormat
},
Fields=“UserEnteredFormat(TextFormat)”
}
};
batchupdateCell.Requests=新列表();
batchupdateCell.Requests.Add(updateCellsRequest);
SpreadsheetsResource.BatchUpdateRequest bur=service.Spreadsheets.BatchUpdate(batchupdateCell,SheetId);
BatchUpdateSpreadsheetResponse responseUpdate3=bur.Execute();

这对我来说很好用,它应该在JSON POST正文和C#/Python/Java/…之间进行几乎1:1的转换。。。类型化资源

POSThttps://sheets.googleapis.com/v4/spreadsheets/YOUR_SPREADSHEET_ID_HERE:batchUpdate?
字段=更新的电子表格(工作表(数据%2行数据%2值%2用户输入格式%2属性(工作表ID%2标题)))

我的请求中的只标识
sheetId
和结束索引,因此它以给定工作表中的所有列为目标,并仅格式化第一行。(根据API规范,结束索引为2将格式化第一行和第二行,除非起始索引为1)


出于验证目的,demo链接被配置为请求Sheets API发回每张工作表上前两行的数据,以及
标题
sheetId
。请注意,如果第二行未应用任何用户格式,则不会为其发送任何数据。

在您的问题中显示您在此处使用的代码,以及您试图修改的代码以及这些修改结果的相应详细信息。请再次查看我的帖子,我会更新它。请检查代码您试图在代码中修改什么?结果是什么?这段代码加粗了我推送的spreedSheet中的所有数据,但我只想加粗标题。我试图删除StartColumnIndex和EndColumnIndex,但结果相同
{
    "requests": [
        {
            "repeatCell": {
                "range": {
                    "sheetId": YOUR_SHEET_ID_HERE,
                    "endRowIndex": 1
                },
                "fields": "userEnteredFormat/textFormat",
                "cell": {
                    "userEnteredFormat": {
                        "textFormat": {
                            "bold": true,
                            "fontSize": 12
                        }
                    }
                }
            }
        }
    ],
    "responseRanges": [
        "1:2"
    ],
    "includeSpreadsheetInResponse": true
}