Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TempRange"/> class.
        /// </summary>
        /// <param name="sourceRange">The original source <see cref="ExcelInterop.Range"/> whose data is copied to the temporary one.</param>
        /// <param name="cropToNonEmptyRange">Flag indicating whether the range is cropped to a sub-range with only non-empty cells.</param>
        /// <param name="skipEmptyColumns">Flag indicating whether empty columns are not copied to the target range.</param>
        /// <param name="hideAndDeleteWorksheet">Flag indicating whether the new temporary <see cref="ExcelInterop.Worksheet"/> will be hidden and deleted when the <see cref="TempRange"/> is disposed.</param>
        /// <param name="limitRowsQuantity">Gets a limit on the number of rows copied from the source range to the temporary range. If less than 1 it means there is no limit.</param>
        /// <param name="disableScreenUpdating">Flag indicating whether screen updating will be disabled to speed up processing.</param>
        private TempRange(ExcelInterop.Range sourceRange, bool cropToNonEmptyRange, bool skipEmptyColumns, bool hideAndDeleteWorksheet, int limitRowsQuantity = 0, bool disableScreenUpdating = true)
        {
            _disableScreenUpdating = disableScreenUpdating;
            _disposed = false;
            _previousScreenUpdatingValue = false;
            if (_disableScreenUpdating)
            {
                _previousScreenUpdatingValue = Globals.ThisAddIn.Application.ScreenUpdating;
                Globals.ThisAddIn.Application.ScreenUpdating = false;
            }

            Globals.ThisAddIn.UsingTempWorksheet = true;
            CropToNonEmptyRange    = cropToNonEmptyRange;
            HideAndDeleteWorksheet = hideAndDeleteWorksheet;
            LimitRowsQuantity      = limitRowsQuantity;
            SkipEmptyColumns       = skipEmptyColumns;
            OriginalSourceRange    = sourceRange;
            SourceRange            = CropToNonEmptyRange
        ? OriginalSourceRange.GetNonEmptyRectangularAreaRange()
        : OriginalSourceRange;
            CreateTempWorksheet();
        }