Beispiel #1
0
        public void AdjustMultipleSheetsColumnsRangesWidthDiemansions(LiveSpreadsheetsDb db, IList <Tuple <string, int, int, int> > columnsRangesDiemansionsAdjustmentBlueprint)
        {
            // Validate provided blueprints
            foreach (Tuple <string, int, int, int> columnRangeDiemansionsAdjustmentBlueprint in columnsRangesDiemansionsAdjustmentBlueprint)
            {
                string sheetTitleId              = columnRangeDiemansionsAdjustmentBlueprint.Item1;
                int    leftColumnIndex           = columnRangeDiemansionsAdjustmentBlueprint.Item2;
                int    columnsToAssureWidthCount = columnRangeDiemansionsAdjustmentBlueprint.Item3;
                int    columnWidthPixelsCount    = columnRangeDiemansionsAdjustmentBlueprint.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 (leftColumnIndex < 0 || leftColumnIndex > blueprintSheet.RightIndex)
                {
                    throw new ArgumentException("At least one provided blueprint has left column index outside of the scope the current sheet.", nameof(leftColumnIndex));
                }
                else if (leftColumnIndex + columnsToAssureWidthCount - 1 < 0 || columnsToAssureWidthCount < 1)
                {
                    throw new ArgumentException("At least one provided blueprint describes range outside of the scope of the current sheet.", nameof(columnsToAssureWidthCount));
                }
                else if (columnWidthPixelsCount < 0)
                {
                    throw new ArgumentException("At least one provided blueprint columnWidthPixelsCount is less then 0.", nameof(columnWidthPixelsCount));
                }
            }

            // 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 columnsRangesDiemansionsAdjustmentBlueprint create associated sheetId containing tuple blueprint,
            // and return the list containing all of them.
            List <Tuple <int?, int, int, int> > columnsRangesDiemansionsAdjustmentSheetIdBlueprint = columnsRangesDiemansionsAdjustmentBlueprint.Select((columnRangeDiemansionsAdjustmentBlueprint) =>
            {
                // 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[columnRangeDiemansionsAdjustmentBlueprint.Item1].SheetId, columnRangeDiemansionsAdjustmentBlueprint.Item2, columnRangeDiemansionsAdjustmentBlueprint.Item3, columnRangeDiemansionsAdjustmentBlueprint.Item4));
            }).ToList();

            // Adjusts multiple columns ranges width dimensions.
            sheetsService.AdjustMultipleColumnsRangesWidthDimensionsSync(this.SpreadsheetId, columnsRangesDiemansionsAdjustmentSheetIdBlueprint);
        }