Пример #1
0
        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);
        }