public UpdateValuesResponse Update(string range, ValueRange body)
        {
            UpdateRequest request = _service.Spreadsheets.Values.Update(body, SheetId(), range);

            request.ValueInputOption = UpdateRequest.ValueInputOptionEnum.USERENTERED;
            return(request.Execute());
        }
        private void UpdateSpreadsheet(ValueRange valueRange, string range)
        {
            UpdateRequest request = SheetsService.Spreadsheets.Values.Update(valueRange, Constants.SpreadsheetId, range);

            request.ValueInputOption = UpdateRequest.ValueInputOptionEnum.USERENTERED;

            request.Execute();

            FormatSpreadsheet();
        }
Exemple #3
0
        /// <summary>
        /// Atualiza o valor de uma célula da planilha.
        /// </summary>
        /// <param name="cell">Índice da célula a ser atualizada. Exemplo: A2.</param>
        /// <param name="newValue">Novo valor da célula.</param>
        /// <returns>Resposta do request da operação.</returns>
        public UpdateValuesResponse UpdateCell(string cell, object newValue)
        {
            List <object> oblist = new List <object>()
            {
                newValue
            };

            ValueRange valueRange = new ValueRange();

            valueRange.Values = new List <IList <object> > {
                oblist
            };

            UpdateRequest updateRequest = service.Spreadsheets.Values.Update(valueRange, spreadsheetId, cell);

            updateRequest.ValueInputOption = UpdateRequest.ValueInputOptionEnum.USERENTERED;

            return(updateRequest.Execute());
        }
Exemple #4
0
        public void SetValuesForCellsAt <T>(TableIndex index, List <List <T> > values)
        {
            var body = new ValueRange
            {
                Values = values.Select(v => v.Cast <object>().ToList())
                         .Cast <IList <object> >()
                         .ToList(),
                MajorDimension = Direction.Horizontal.ToGoogleDimension()
            };

            var range = new TableIndexRange(index, index
                                            .WithRow(index.Row + values.Count - 1)
                                            .WithColumn(index.Column + values.Select(v => v.Count).Max() - 1));

            UpdateRequest request = SheetsService.Spreadsheets.Values.Update(body, SpreadsheetId, range.ToString());

            request.ValueInputOption = USERENTERED;

            request.Execute();
        }
        public virtual void AddPixelsForUser(string userName, int numPixelsToAdd, string actingUser)
        {
            SheetsService           service;
            IList <IList <object> > values;

            GetSheetService(out service, out values);

            userName = userName.ToLowerInvariant().Trim();

            var thisRow = values.FirstOrDefault(r => r[0].ToString().Trim().ToLowerInvariant() == userName);

            if (thisRow == null)
            {
                Logger.LogDebug($"Adding row for {userName}");

                var rangeToSet = new List <IList <object> > {
                    new List <object> {
                        userName, numPixelsToAdd
                    }
                };
                var append = new AppendCellsRequest();
                append.SheetId = 0;
                append.Fields  = "*";
                var newRow = new RowData()
                {
                    Values = new List <CellData> {
                    }
                };
                newRow.Values.Add(new CellData {
                    UserEnteredValue = new ExtendedValue {
                        StringValue = userName
                    }
                });
                newRow.Values.Add(new CellData {
                    UserEnteredValue = new ExtendedValue {
                        NumberValue = numPixelsToAdd
                    }, UserEnteredFormat = new CellFormat {
                        HorizontalAlignment = "CENTER"
                    }
                });

                append.Rows = new[] { newRow };
                var appendRequest = new Request();
                appendRequest.AppendCells = append;
                service.Spreadsheets.BatchUpdate(new BatchUpdateSpreadsheetRequest {
                    Requests = new[] { appendRequest }
                }, Spreadsheet).Execute();

                ResortSpreadsheet(service);

                LogActivityOnSheet(service, actingUser, userName, "Add", numPixelsToAdd);

                Twitch.BroadcastMessageOnChannel($"Successfully granted {userName} their first {numPixelsToAdd} {_CurrencyName}!");
            }
            else
            {
                Logger.LogDebug($"Updating row for {userName}");

                var pos      = values.IndexOf(thisRow);
                var newValue = (int.Parse(thisRow.Count < 2 ? "0" : thisRow[1].ToString())) + numPixelsToAdd;
                if (newValue < 0)
                {
                    newValue = 0;
                }
                var rangeToSet = new List <IList <object> > {
                    new List <object> {
                        newValue
                    }
                };

                UpdateRequest update = service.Spreadsheets.Values.Update(
                    new Google.Apis.Sheets.v4.Data.ValueRange {
                    Values = rangeToSet, Range = $"Pixels!B{4 + pos}"
                },
                    Spreadsheet,
                    $"Pixels!B{4 + pos}"
                    );
                update.ValueInputOption = UpdateRequest.ValueInputOptionEnum.USERENTERED;
                update.Execute();

                LogActivityOnSheet(service, actingUser, userName, "Add", numPixelsToAdd);

                Twitch.BroadcastMessageOnChannel($"Successfully granted {userName} an additional {numPixelsToAdd} {_CurrencyName}.  Their new total is {newValue} {_CurrencyName}");
            }
        }