// Adds the new instance of the LiveSheet into the current LiveSpreadsheet. public void AddSheet <Row, Cell>(LiveSpreadsheetsDb db, string sheetTitleId, int columnCount, int rowCount, IList <Row> rowData) where Row : class, IList <Cell> where Cell : class { // Validate provided parameters and throw appropriate exception if unable to proceed. if (this._sheetsIndex.ContainsKey(sheetTitleId)) { throw new ArgumentException($"Unable to add LiveSheet indexed to provided sheet title id {sheetTitleId} because current LiveSpreadsheet already contains the sheet using the same sheet title id.", nameof(sheetTitleId)); } else if (columnCount < 1) { throw new ArgumentException("Unable to create a sheet with less then one column. Please provide column count greater then 0.", nameof(columnCount)); } else if (rowCount < 1) { throw new ArgumentException("Unable to create a sheet with less then one row. Please provide row count greater then 0.", nameof(rowCount)); } // Add sheet into the appropriate spreadsheet db.ApisSheetsService.AddSheetSync(this.SpreadsheetId, sheetTitleId, columnCount, rowCount); // Construct new instance of LiveSheet LiveSheet sheet = LiveSheet.Factory.GetSheet <Row, Cell>(this.SpreadsheetId, sheetTitleId, columnCount, rowCount, rowData); sheet.Upload(db); // Add sheet into the current LiveSpreadsheet sheets index. this._sheetsIndex.Add(sheetTitleId, sheet); }
// Re obtains the data using provided google sheets service. public async Task ReObtainDataAsync(LiveSpreadsheetsDb db) { // Obtain data from google sheets service. IList <object> currentData = await db.ApisSheetsService.GetObjectsRowDataAsync(this.SpreadsheetId, this.Range); // Set current LiveCel data. this.SetDataFromCellsData <object>(0, currentData, false); }
// Re obtains the data using provided google sheets service. public void ReObtainData(LiveSpreadsheetsDb db) { // Obtain data from google sheets service. object currentData = db.ApisSheetsService.GetObjectCellDataSync(this.SpreadsheetId, this.Range); // Set current LiveCel data. this.SetData(currentData, false); }
// Assures that the data currently stored in the LiveRow is persisted on google servers public void Upload(LiveSpreadsheetsDb db) { // Get the row data in the form understandable to google service. IList <IList <object> > rows = this.GetDataAsObjectsGrid(); // Using provided google service update data stored by row into the google servers db.ApisSheetsService.UpdateRangeDataSync(this.SpreadsheetId, this.Range, rows); }
// Re obtains the data using provided google sheets service. public void ReObtainData(LiveSpreadsheetsDb db) { // Obtain current data grid from the provided google service IList <IList <object> > currentData = db.ApisSheetsService.GetObjectsRangeDataSync(this.SpreadsheetId, this.Range); // 0, 0 representing buffer values this.SetDataFromRowsData <IList <object>, object>(0, 0, currentData, false); }
// Assures that the data currently stored in the LiveRow is persisted on google servers public async Task UploadAsync(LiveSpreadsheetsDb db) { // Get the row data in the form understandable to google service. IList <IList <object> > rows = new IList <object>[1] { this.GetDataAsObjects() }; // Using provided google service update data stored by row into the google servers await db.ApisSheetsService.UpdateRangeDataAsync(this.SpreadsheetId, this.Range, rows); }
// Removes instance of the LiveSheet indexed into the current LiveSpreadsheet instance. public void RemoveSheet(LiveSpreadsheetsDb db, string sheetTitleId) { // Validate provided parameters and throw appropriate exception if unable to proceed. if (!this._sheetsIndex.ContainsKey(sheetTitleId)) { throw new ArgumentException($"Unable to remove LiveSheet indexed to provided sheet title id {sheetTitleId} because current LiveSpreadsheet doesn't contain any sheet indexed to that specific sheet title id.", nameof(sheetTitleId)); } throw new NotImplementedException(); }
public void AdjustMultipleRowsRangesHeightDiemansions(LiveSpreadsheetsDb db, IList <Tuple <string, int, int, int> > rowsRangesDiemansionsAdjustmentBlueprint) { foreach (Tuple <string, int, int, int> rowRangeDiemansionsAdjustmentBlueprint in rowsRangesDiemansionsAdjustmentBlueprint) { string sheetTitleId = rowRangeDiemansionsAdjustmentBlueprint.Item1; int topRowIndex = rowRangeDiemansionsAdjustmentBlueprint.Item2; int rowsToAssureHeightCount = rowRangeDiemansionsAdjustmentBlueprint.Item3; int rowWidthPixelsCount = rowRangeDiemansionsAdjustmentBlueprint.Item4; this._sheetsIndex.TryGetValue(sheetTitleId, out LiveSheet blueprintSheet); if (blueprintSheet is null) { throw new ArgumentException("At least one provided blueprint has sheet title id unrelated with any of the sheets containing by the current spreadsheet.", nameof(sheetTitleId)); } else if (topRowIndex < 0 || topRowIndex > blueprintSheet.BottomIndex) { throw new ArgumentException("At least one provided blueprint has top row index outside of the scope the current sheet.", nameof(topRowIndex)); } else if (topRowIndex + rowsToAssureHeightCount - 1 < 0 || rowsToAssureHeightCount < 1) { throw new ArgumentException("At least one provided blueprint describes range outside of the scope of the current sheet.", nameof(rowsToAssureHeightCount)); } else if (rowWidthPixelsCount < 0) { throw new ArgumentException("At least one provided blueprint rownWidthPixelsCount is less then 0.", nameof(rowWidthPixelsCount)); } } // Get google apis SheetsService instance SheetsService sheetsService = db.ApisSheetsService; // if current sheet SheetId is null, obtain it from based on the sheet title id. foreach (LiveSheet sheet in this.Sheets) { if (sheet.SheetId is null) { sheet.SheetId = sheetsService.GetSheetIdFromSheetTitleIdIdSync(this.SpreadsheetId, sheet.SheetTitleId); } } // For each Tuple provided in rowsRangesDiemansionsAdjustmentSheetIdBlueprint create associated sheetId containing tuple blueprint, // and return the list containing all of them. List <Tuple <int?, int, int, int> > rowsRangesDiemansionsAdjustmentSheetIdBlueprint = rowsRangesDiemansionsAdjustmentBlueprint.Select((rowRangeDiemansionsAdjustmentBlueprint) => { // Build sheetId contacting tuple blueprint based on the one provided as a method parameter, without specified sheetId. return(new Tuple <int?, int, int, int>(this[rowRangeDiemansionsAdjustmentBlueprint.Item1].SheetId, rowRangeDiemansionsAdjustmentBlueprint.Item2, rowRangeDiemansionsAdjustmentBlueprint.Item3, rowRangeDiemansionsAdjustmentBlueprint.Item4)); }).ToList(); // Adjusts multiple rows ranges height dimensions. sheetsService.AdjustMultipleRowsRangesHeightDimensionsSync(this.SpreadsheetId, rowsRangesDiemansionsAdjustmentSheetIdBlueprint); }