예제 #1
0
        private async Task CommitSignupRow(Sheet sheetToUpdate, RowData rowToUpdate, int rowIndex)
        {
            var sheetUpdates = new BatchUpdateSpreadsheetRequest();

            sheetUpdates.Requests = new List <Request>()
            {
                new Request()
                {
                    UpdateCells = new UpdateCellsRequest()
                    {
                        Start = new GridCoordinate()
                        {
                            SheetId = sheetToUpdate.Properties.SheetId, RowIndex = rowIndex, ColumnIndex = 0
                        },
                        Fields = "*",
                        Rows   = new List <RowData>()
                        {
                            rowToUpdate
                        }
                    }
                }
            };

            var updateRequest = new SpreadsheetsResource.BatchUpdateRequest(this.SheetsService, sheetUpdates, HeroicSheetsId);

            await updateRequest.ExecuteAsync();
        }
예제 #2
0
        public async Task <BatchUpdateSpreadsheetResponse> RenameSheet(string spreadsheetId, int sheetId, string oldName, string newName)
        {
            var req = new BatchUpdateSpreadsheetRequest
            {
                Requests = new List <Request>
                {
                    new Request
                    {
                        UpdateSheetProperties = new UpdateSheetPropertiesRequest
                        {
                            Properties = new SheetProperties
                            {
                                SheetId = sheetId,
                                Title   = newName
                            }
                        }
                    }
                }
            };

            SpreadsheetsResource.BatchUpdateRequest request = new SpreadsheetsResource.BatchUpdateRequest(_sheetsService, req, spreadsheetId);
            var response = await request.ExecuteAsync();

            return(response);
        }
        private async void HighlightCellAsync(int row, int col)
        {
            Google.Apis.Sheets.v4.Data.BatchUpdateSpreadsheetRequest requestBody = new Google.Apis.Sheets.v4.Data.BatchUpdateSpreadsheetRequest();

            // Send a request that get the range, set the background color to highlight yellow, and set the date as today
            requestBody.Requests = new List <Google.Apis.Sheets.v4.Data.Request>()
            {
                new Request()
                {
                    RepeatCell = new RepeatCellRequest()
                    {
                        Range = new GridRange()
                        {
                            SheetId          = this.SheetID,
                            StartRowIndex    = row,
                            EndRowIndex      = row + 1,
                            StartColumnIndex = col,
                            EndColumnIndex   = col + 1
                        },
                        Cell = new CellData()
                        {
                            UserEnteredFormat = new CellFormat()
                            {
                                BackgroundColor = new Color()
                                {
                                    Red   = 1,
                                    Green = 1,
                                    Blue  = 0
                                },
                            },
                            UserEnteredValue = new ExtendedValue()
                            {
                                StringValue = DateTime.Today.ToString("MM/dd/yyyy")
                            }
                        },
                        Fields = "userEnteredValue,userEnteredFormat.backgroundColor"
                    },
                }
            };

            // Send the request
            SpreadsheetsResource.BatchUpdateRequest request = Service.Spreadsheets.BatchUpdate(requestBody, this.SpreadSheetID);
            Google.Apis.Sheets.v4.Data.BatchUpdateSpreadsheetResponse response = await request.ExecuteAsync();

            Console.WriteLine(JsonConvert.SerializeObject(response));
        }