Beispiel #1
0
        // Adjust the pixelSize rows height.
        internal static SpreadsheetsResource.BatchUpdateRequest GetAdjustRowsHeightDimensionRequest(SheetsService sheetsService, string spreadsheetId, int?sheetId, int topRowIndex, int rowsToAdjustHeightCount, int rowHeightPixelsCount)
        {
            // If provided sheetId is null, throw appropriate exception.
            if (sheetId is null)
            {
                throw new ArgumentNullException(nameof(sheetId));
            }

            // Create appropriate partial request of type UpdateDimensionPropertiesRequest, where rows are considered as the dimension to adjust size.
            UpdateDimensionPropertiesRequest updateDimensionPropertiesRequest = GoogleServicesExtensionsRequestsFactory.GetAdjustRowsHeightDimensionPartialRequest(spreadsheetId, sheetId, topRowIndex, rowsToAdjustHeightCount, rowHeightPixelsCount);

            // Construct new batch update request body..
            BatchUpdateSpreadsheetRequest batchUpdateSpreadsheetRequest = new BatchUpdateSpreadsheetRequest();

            // .. initialize new list of partial requests ..
            batchUpdateSpreadsheetRequest.Requests = new List <Request>();
            // .. and add appropriate partial request.
            batchUpdateSpreadsheetRequest.Requests.Add(new Request {
                UpdateDimensionProperties = updateDimensionPropertiesRequest
            });

            // Set ResponseIncludeGridData flag to false to increase performance.
            batchUpdateSpreadsheetRequest.ResponseIncludeGridData = false;

            // Construct and return appropriate batch update request based on the provided request body and spreadsheet id.
            return(sheetsService.Spreadsheets.BatchUpdate(batchUpdateSpreadsheetRequest, spreadsheetId));
        }
Beispiel #2
0
        // Adjust the pixelSize width of the multiple specified rows ranges.
        internal static SpreadsheetsResource.BatchUpdateRequest GetAdjustMultipleRowsRangesHeightDimensionsRequest(SheetsService sheetsService, string commonSpreadsheetId, IList <Tuple <int?, int, int, int> > rowsRangesDimensionsAdjustmentBlueprint)
        {
            // Declare partial requests list container.
            IList <Request> requests = new List <Request>();

            // Loop through all the columns ranges dimensions adjustment blueprints.
            foreach (Tuple <int?, int, int, int> rowRangeDiemansionsAdjustmentBlueprint in rowsRangesDimensionsAdjustmentBlueprint)
            {
                // Obtain sheet id from currently looped through Tuple blueprint
                int?sheetId = rowRangeDiemansionsAdjustmentBlueprint.Item1 ?? throw new ArgumentNullException(nameof(sheetId));

                // Obtain index of the most top row which height will be affected.
                int topRowIndex = rowRangeDiemansionsAdjustmentBlueprint.Item2;

                // Obtain number of rows to adjust start counting from the one specified with topRowIndex to the bottom.
                int rowsToAdjustHeightCount = rowRangeDiemansionsAdjustmentBlueprint.Item3;

                // Obtain height in pixels of the rows in the range after adjustment.
                int rowHeightPixelsCount = rowRangeDiemansionsAdjustmentBlueprint.Item4;

                // Get appropriate partial update columns width dimensions request ...
                UpdateDimensionPropertiesRequest updateDimensionPropertiesRequest = GoogleServicesExtensionsRequestsFactory.GetAdjustRowsHeightDimensionPartialRequest(commonSpreadsheetId, sheetId, topRowIndex, rowsToAdjustHeightCount, rowHeightPixelsCount);

                // .. and add it into the collection contain all the partial requests.
                requests.Add(new Request {
                    UpdateDimensionProperties = updateDimensionPropertiesRequest
                });
            }

            // Construct new batch update request body..
            BatchUpdateSpreadsheetRequest batchUpdateSpreadsheetRequest = new BatchUpdateSpreadsheetRequest();

            // .. initialize and assign gathered collection of partial requests.
            batchUpdateSpreadsheetRequest.Requests = requests;

            // Set ResponseIncludeGridData flag to false to increase performance.
            batchUpdateSpreadsheetRequest.ResponseIncludeGridData = false;

            // Construct and return appropriate batch update request based on the provided request body and spreadsheet id.
            return(sheetsService.Spreadsheets.BatchUpdate(batchUpdateSpreadsheetRequest, commonSpreadsheetId));
        }