UpdateCellRequest会覆盖电子表格中的单元格格式

时间:2016-08-31 08:32:53

标签: c# google-sheets google-spreadsheet-api google-api-dotnet-client google-sheets-api

将c#client用于API的v4。

按如下方式创建请求:

var updateValuesRequest = new Request() { 
    UpdateCells = new UpdateCellsRequest() { 
        Rows = range.rows, 
        Start = new GridCoordinate() { 
            SheetId = sheetId, 
            RowIndex = range.rowIndex, 
            ColumnIndex = range.columnIndex 
        }, 
        Fields = "*" 
    } 
};

在定义CellData时我没有指定CellFormat,它仍然会通过某些默认格式覆盖工作表中的现有单元格格式。

如何通过API更新值时确保不更改现有单元格格式?

1 个答案:

答案 0 :(得分:2)

You specified "*" as your fields, meaning you are asking to overwrite every field. If the data for the field isn't present, then that means to revert it to the default.

If you want to only set some specific portions of the data, you must list those fields explicitly in "fields".

See https://developers.google.com/sheets/guides/batchupdate#field_masks for more information.