Пример #1
0
 private void UseRangeAsDataSource()
 {
     #region #RangeAsDataSource
     RangeDataSourceOptions options = new RangeDataSourceOptions();
     Worksheet sheet     = spreadsheetControl1.ActiveWorksheet;
     CellRange dataRange = sheet.Selection;
     if (dataRange.Equals(sheet.Tables[0].Range))
     {
         options.UseFirstRowAsHeader = true;
     }
     else
     {
         options.UseFirstRowAsHeader          = false;
         options.DataSourceColumnTypeDetector = new MyColumnDetector();
     }
     options.SkipHiddenColumns = true;
     rangeDS = dataRange.GetDataSource(options);
     sheet.DataBindings.Error += DataBindings_Error;
     #endregion #RangeAsDataSource
     BindControlsToDataSource();
 }
Пример #2
0
        void ExecuteDragFillClear(Excel excel)
        {
            _clearValueUndoAction.Execute(excel);
            CellRange startRange = _dragFillExtent.StartRange;
            CellRange fillRange  = _dragFillExtent.FillRange;

            if (!startRange.Equals(fillRange))
            {
                if (_fillSeries == FillSeries.Column)
                {
                    CellRange range = new CellRange(startRange.Row, startRange.Column, startRange.RowCount - fillRange.RowCount, startRange.ColumnCount);
                    excel.SetActiveCell(Math.Max(0, range.Row), Math.Max(0, range.Column), true);
                    _workSheet.SetSelection(range);
                }
                else
                {
                    CellRange range4 = new CellRange(startRange.Row, startRange.Column, startRange.RowCount, startRange.ColumnCount - fillRange.ColumnCount);
                    excel.SetActiveCell(Math.Max(0, range4.Row), Math.Max(0, range4.Column), true);
                    _workSheet.SetSelection(range4);
                }
            }
        }
Пример #3
0
        public void KeyboardSelect(NavigationDirection direction)
        {
            CellRange selectionRange = GetSelectionRange();

            if (selectionRange != null)
            {
                KeyboardSelectKind keyboardSelectionKind = GetKeyboardSelectionKind(direction);
                CellRange          range = null;
                switch (keyboardSelectionKind)
                {
                case KeyboardSelectKind.Line:
                    range = KeyboardLineSelect(selectionRange, direction, true);
                    if (range == null)
                    {
                        range = KeyboardLineSelect(selectionRange, direction, false);
                    }
                    break;

                case KeyboardSelectKind.Page:
                    range = KeyboardPageSelect(selectionRange, direction);
                    break;

                case KeyboardSelectKind.Through:
                    range = KeyboardThroughSelect(selectionRange, direction);
                    break;
                }
                if ((range != null) && !range.Equals(selectionRange))
                {
                    CellRange[] oldSelection = Enumerable.ToArray <CellRange>((IEnumerable <CellRange>)_excel.ActiveSheet.Selections);
                    _excel.ActiveSheet.ClearSelection(selectionRange);
                    range = GetExpandIntersectedRange(range);
                    _excel.ActiveSheet.AddSelection(range, false);
                    if (_excel.RaiseSelectionChanging(oldSelection, Enumerable.ToArray <CellRange>((IEnumerable <CellRange>)_excel.ActiveSheet.Selections)))
                    {
                        _excel.RaiseSelectionChanged();
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Extends the selection.
        /// </summary>
        /// <param name="row">The row index to which to extend the selection.</param>
        /// <param name="column">The column index to which to extend the selection.</param>
        /// <param name="rowCount">The number of rows to which to extend the selection.</param>
        /// <param name="columnCount">The number of columns to which to extend the selection.</param>
        public override void ExtendSelection(int row, int column, int rowCount, int columnCount)
        {
            int num;
            int num2;
            int num3;
            int num4;

            if ((row == -1) && (column == -1))
            {
                num  = -1;
                num3 = -1;
                num2 = -1;
                num4 = -1;
            }
            else if (row == -1)
            {
                num  = -1;
                num3 = -1;
                num2 = Math.Min(this.anchorColumn, column);
                num4 = (Math.Max(this.anchorColumn, column) - num2) + 1;
            }
            else if (column == -1)
            {
                num  = Math.Min(this.anchorRow, row);
                num3 = (Math.Max(this.anchorRow, row) - num) + 1;
                num2 = -1;
                num4 = -1;
            }
            else
            {
                num  = row;
                num3 = rowCount;
                num2 = column;
                num4 = columnCount;
            }
            if (this.selectionPolicy != Dt.Cells.Data.SelectionPolicy.Single)
            {
                if (this.selectionPolicy == Dt.Cells.Data.SelectionPolicy.Range)
                {
                    while (this.items.Count > 1)
                    {
                        CellRange range = this.items[0];
                        base.FireChanged(range.Row, range.Column, range.RowCount, range.ColumnCount);
                        this.items.RemoveAt(0);
                    }
                }
                if (this.selectionUnit == Dt.Cells.Data.SelectionUnit.Row)
                {
                    num2 = -1;
                    num4 = -1;
                }
                else if (this.selectionUnit == Dt.Cells.Data.SelectionUnit.Column)
                {
                    num  = -1;
                    num3 = -1;
                }
                if ((this.selectionUnit == Dt.Cells.Data.SelectionUnit.Row) && !this.IsSelected(this.anchorRow, this.anchorColumn))
                {
                    this.RemoveSelection(num, num2, num3, num4);
                }
                else if (this.items.Count <= 0)
                {
                    CellRange range6 = new CellRange(num, num2, num3, num4);
                    this.items.Add(range6);
                    base.FireChanged(range6.Row, range6.Column, range6.RowCount, range6.ColumnCount);
                }
                else
                {
                    CellRange range2 = null;
                    int       num5   = this.items.Count - 1;
                    while (num5 >= 0)
                    {
                        if (this.items[num5].Contains(this.anchorRow, this.anchorColumn))
                        {
                            range2 = this.items[num5];
                            break;
                        }
                        num5--;
                    }
                    CellRange original = new CellRange(num, num2, num3, num4);
                    if (!original.Equals(range2))
                    {
                        if (range2 != null)
                        {
                            this.items[num5] = original;
                            List <CellRange> items = new List <CellRange>();
                            this.Split(items, original, range2);
                            foreach (CellRange range4 in items)
                            {
                                base.FireChanged(range4.Row, range4.Column, range4.RowCount, range4.ColumnCount);
                            }
                            items.Clear();
                            this.Split(items, range2, original);
                            foreach (CellRange range5 in items)
                            {
                                base.FireChanged(range5.Row, range5.Column, range5.RowCount, range5.ColumnCount);
                            }
                        }
                        else
                        {
                            this.items.Add(original);
                            base.FireChanged(original.Row, original.Column, original.RowCount, original.ColumnCount);
                        }
                    }
                }
            }
        }