コード例 #1
0
        // TODO
        #endregion

        #region Adjust Columns/Rows Width/Height Dimension
        // Adjust the pixelSize columns width.
        internal static SpreadsheetsResource.BatchUpdateRequest GetAdjustColumnsWidthDimensionRequest(SheetsService sheetsService, string spreadsheetId, int?sheetId, int leftColumnIndex, int columnsToAdjustWidthCount, int columnWidthPixelsCount)
        {
            // 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 columns are considered as the dimension to adjust size.
            UpdateDimensionPropertiesRequest updateDimensionPropertiesRequest = GoogleServicesExtensionsRequestsFactory.GetAdjustColumnsWidthDimensionPartialRequest(spreadsheetId, sheetId, leftColumnIndex, columnsToAdjustWidthCount, columnWidthPixelsCount);

            // 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));
        }
コード例 #2
0
        // Adjust the pixelSize width of the multiple specified columns ranges.
        internal static SpreadsheetsResource.BatchUpdateRequest GetAdjustMultipleColumnsRangesWidthDimensionsRequest(SheetsService sheetsService, string commonSpreadsheetId, IList <Tuple <int?, int, int, int> > columnsRangesDimensionsAdjustmentBlueprint)
        {
            // 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> columnRangeDimensionsAdjustmentBlueprint in columnsRangesDimensionsAdjustmentBlueprint)
            {
                // Obtain sheet id from currently looped through Tuple blueprint
                int?sheetId = columnRangeDimensionsAdjustmentBlueprint.Item1 ?? throw new ArgumentNullException(nameof(sheetId));

                // Obtain index of the most left column which width will be affected.
                int leftColumnIndex = columnRangeDimensionsAdjustmentBlueprint.Item2;

                // Obtain number of columns to adjust start counting from the one specified with leftColumnIndex to the right.
                int columnsToAdjustWidthCount = columnRangeDimensionsAdjustmentBlueprint.Item3;

                // Obtain width in pixels of the columns in the range after adjustment.
                int columnWidthPixelsCount = columnRangeDimensionsAdjustmentBlueprint.Item4;

                // Get appropriate partial update columns width dimensions request ...
                UpdateDimensionPropertiesRequest updateDimensionPropertiesRequest = GoogleServicesExtensionsRequestsFactory.GetAdjustColumnsWidthDimensionPartialRequest(commonSpreadsheetId, sheetId, leftColumnIndex, columnsToAdjustWidthCount, columnWidthPixelsCount);

                // .. 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));
        }