예제 #1
0
        public async Task <Sheet> AddSheet(string name)
        {
            var sheet = new Sheet(this, Sheets.Count, name);

            Sheets.Add(sheet);

            var batchRequest = new BatchUpdateSpreadsheetHelper(ID);

            batchRequest.Add((request) =>
            {
                // By default, a spreadsheet already has one sheet.
                // If there is more than one sheet, create a new one.
                // Otherwise, just update the title of the first one.
                if (Sheets.Count > 1)
                {
                    request.AddSheet = new AddSheetRequest()
                    {
                        Properties = new SheetProperties()
                        {
                            SheetId        = Sheets.Count - 1,
                            Title          = name,
                            GridProperties = new GridProperties()
                            {
                                ColumnCount = 1,
                                RowCount    = 1,
                            }
                        },
                    };
                }
                else
                {
                    request.UpdateSheetProperties = new UpdateSheetPropertiesRequest()
                    {
                        Properties = new SheetProperties()
                        {
                            Title          = name,
                            GridProperties = new GridProperties()
                            {
                                ColumnCount = 1,
                                RowCount    = 1,
                            }
                        },
                        Fields = "*",
                    };
                }
            });

            await batchRequest.ExecuteAsync(Service);

            return(sheet);
        }
예제 #2
0
        private BatchUpdateSpreadsheetHelper CreateUpdateRequest()
        {
            var batchRequest = new BatchUpdateSpreadsheetHelper(spreadSheet.ID);

            batchRequest.Add((request) =>
            {
                request.UpdateSheetProperties = new UpdateSheetPropertiesRequest()
                {
                    Properties = new SheetProperties()
                    {
                        GridProperties = new GridProperties()
                        {
                            RowCount    = this.Rows.Count,
                            ColumnCount = this.Rows[0].Values.Count, // bad
                        },
                        SheetId = ID,
                        Title   = Name,
                    },
                    Fields = "*",
                };
            });

            batchRequest.Add((request) =>
            {
                request.UpdateCells = new UpdateCellsRequest()
                {
                    Start = new GridCoordinate()
                    {
                        SheetId     = ID,
                        RowIndex    = 0,
                        ColumnIndex = 0,
                    },
                    Rows   = this.Rows,
                    Fields = "*",
                };
            });

            return(batchRequest);
        }