Пример #1
0
        /// <summary>
        /// Saves the state for undoing the action before executing the action.
        /// </summary>
        public void SaveState()
        {
            CellRange         range     = AdjustRange(_arrayFormulaRange);
            CopyMoveCellsInfo cellsInfo = new CopyMoveCellsInfo(range.RowCount, range.ColumnCount);

            CopyMoveHelper.SaveViewportInfo(_workSheet, cellsInfo, range.Row, range.Column, CopyToOption.All);
            _savedArrayFormulaViewportCells = cellsInfo;
        }
Пример #2
0
        CopyMoveCellsInfo SaveRangeStates(CellRange range)
        {
            CellRange         range2    = AdjustRange(range);
            CopyMoveCellsInfo cellsInfo = new CopyMoveCellsInfo(range2.RowCount, range2.ColumnCount);

            CopyMoveHelper.SaveViewportInfo(_workSheet, cellsInfo, range2.Row, range2.Column, CopyToOption.All);
            return(cellsInfo);
        }
Пример #3
0
        void SaveDragFillState()
        {
            CellRange fillRange = _dragFillExtent.FillRange;

            _savedFilledViewportCells = SaveRangeStates(_dragFillExtent.FillRange);
            _savedStartViewportCells  = SaveRangeStates(_dragFillExtent.StartRange);
            SaveFillRangeTables();
        }
Пример #4
0
 public static void SaveViewportInfo(Worksheet sheet, CopyMoveCellsInfo cellsInfo, int baseRow, int baseColumn, CopyToOption option)
 {
     if ((option & CopyToOption.All) > ((CopyToOption)0))
     {
         int rowCount    = cellsInfo.RowCount;
         int columnCount = cellsInfo.ColumnCount;
         for (int i = 0; i < rowCount; i++)
         {
             for (int j = 0; j < columnCount; j++)
             {
                 if ((option & CopyToOption.Value) > ((CopyToOption)0))
                 {
                     cellsInfo.SaveValue(i, j, sheet.GetValue(baseRow + i, baseColumn + j, SheetArea.Cells));
                 }
                 if (((option & CopyToOption.Value) > ((CopyToOption)0)) || ((option & CopyToOption.Formula) > ((CopyToOption)0)))
                 {
                     cellsInfo.SaveFormula(i, j, sheet.GetFormula(baseRow + i, baseColumn + j));
                     object[,] arrayFormulas = Excel.GetsArrayFormulas(sheet, baseRow, baseColumn, rowCount, columnCount);
                     cellsInfo.SaveArrayFormula(arrayFormulas);
                 }
                 if ((option & CopyToOption.Sparkline) > ((CopyToOption)0))
                 {
                     Sparkline sparkline              = sheet.GetSparkline(baseRow + i, baseColumn + j);
                     CellRange sparklineDataRange     = sheet.Cells[baseRow + i, baseColumn + j].SparklineDataRange;
                     CellRange sparklineDateAxisRange = sheet.Cells[baseRow + i, baseColumn + j].SparklineDateAxisRange;
                     if ((sparkline != null) && (sparklineDataRange != null))
                     {
                         cellsInfo.SaveSparkline(i, j, new SparklineInfo(sparkline, sparklineDataRange, sparklineDateAxisRange));
                     }
                     else
                     {
                         cellsInfo.SaveSparkline(i, j, null);
                     }
                 }
                 if ((option & CopyToOption.Style) > ((CopyToOption)0))
                 {
                     cellsInfo.SaveStyle(i, j, GetStyleObject(sheet, baseRow + i, baseColumn + j, SheetArea.Cells));
                 }
                 if ((option & CopyToOption.Tag) > ((CopyToOption)0))
                 {
                     cellsInfo.SaveTag(i, j, sheet.GetTag(baseRow + i, baseColumn + j, SheetArea.Cells));
                 }
             }
         }
         if ((option & CopyToOption.Span) > ((CopyToOption)0))
         {
             IEnumerator enumerator = sheet.SpanModel.GetEnumerator(baseRow, baseColumn, rowCount, columnCount);
             while (enumerator.MoveNext())
             {
                 cellsInfo.SaveSpan((CellRange)enumerator.Current);
             }
         }
     }
 }
Пример #5
0
 void InitSaveState()
 {
     _savedFromColumnHeaderCells = null;
     _savedFromColumns           = null;
     _savedFromViewportCells     = null;
     _savedFromRowHeaderCells    = null;
     _savedFromRows            = null;
     _savedFromFloatingObjects = null;
     _savedToColumnHeaderCells = null;
     _savedToColumns           = null;
     _savedToViewportCells     = null;
     _savedToRowHeaderCells    = null;
     _savedToRows                    = null;
     _savedToFloatingObjects         = null;
     _savedAcitveRowViewportIndex    = -2;
     _savedAcitveColumnViewportIndex = -2;
     _savedActiveRow                 = -1;
     _savedActiveColumn              = -1;
 }
Пример #6
0
        void UndoRangeStates(CopyMoveCellsInfo savedInfo, CellRange range)
        {
            CellRange range2 = AdjustRange(range);

            CopyMoveHelper.UndoCellsInfo(_workSheet, savedInfo, range2.Row, range2.Column, SheetArea.Cells);
        }
Пример #7
0
        public static void UndoCellsInfo(Worksheet sheet, CopyMoveCellsInfo cellsInfo, int baseRow, int baseColumn, SheetArea area)
        {
            int rowCount    = cellsInfo.RowCount;
            int columnCount = cellsInfo.ColumnCount;

            sheet.SuspendCalcService();
            try
            {
                for (int i = 0; i < rowCount; i++)
                {
                    for (int j = 0; j < columnCount; j++)
                    {
                        if (cellsInfo.IsFormulaSaved() && (area == SheetArea.Cells))
                        {
                            sheet.SetFormula(baseRow + i, baseColumn + j, null);
                        }
                        if (cellsInfo.IsSparklineSaved() && (area == SheetArea.Cells))
                        {
                            sheet.RemoveSparkline(baseRow + i, baseColumn + j);
                        }
                        if (cellsInfo.IsValueSaved())
                        {
                            sheet.SetValue(baseRow + i, baseColumn + j, area, null);
                        }
                        if (cellsInfo.IsStyleSaved())
                        {
                            SetStyleObject(sheet, baseRow + i, baseColumn + j, area, null);
                        }
                        if (cellsInfo.IsTagSaved())
                        {
                            sheet.SetTag(baseRow + i, baseColumn + j, area, null);
                        }
                    }
                }
                if (cellsInfo.IsFormulaSaved() && (area == SheetArea.Cells))
                {
                    foreach (CellData data in cellsInfo.GetFormulas())
                    {
                        sheet.SetFormula(baseRow + data.Row, baseColumn + data.Column, (string)(data.Value as string));
                    }
                }
                if (cellsInfo.IsSparklineSaved() && (area == SheetArea.Cells))
                {
                    foreach (CellData data2 in cellsInfo.GetSparklines())
                    {
                        SparklineInfo info = data2.Value as SparklineInfo;
                        if (info == null)
                        {
                            ((ISparklineSheet)sheet).SetSparkline(baseRow + data2.Row, baseColumn + data2.Column, null);
                        }
                        else if (info.DataAxisRange == null)
                        {
                            sheet.SetSparkline(baseRow + data2.Row, baseColumn + data2.Column, info.DataRange, info.Sparkline.DataOrientation, info.Sparkline.SparklineType, info.Sparkline.Setting);
                        }
                        else
                        {
                            sheet.SetSparkline(baseRow + data2.Row, baseColumn + data2.Column, info.DataRange, info.Sparkline.DataOrientation, info.Sparkline.SparklineType, info.DataAxisRange, info.Sparkline.DateAxisOrientation, info.Sparkline.Setting);
                        }
                    }
                }
                if (cellsInfo.IsValueSaved())
                {
                    foreach (CellData data3 in cellsInfo.GetValues())
                    {
                        sheet.SetValue(baseRow + data3.Row, baseColumn + data3.Column, area, data3.Value);
                    }
                }
                if (cellsInfo.IsStyleSaved())
                {
                    foreach (CellData data4 in cellsInfo.GetStyles())
                    {
                        SetStyleObject(sheet, baseRow + data4.Row, baseColumn + data4.Column, area, data4.Value);
                    }
                }
                if (cellsInfo.IsTagSaved())
                {
                    foreach (CellData data5 in cellsInfo.GetTags())
                    {
                        sheet.SetTag(baseRow + data5.Row, baseColumn + data5.Column, area, data5.Value);
                    }
                }
                if (cellsInfo.IsArrayFormulaSaved() && (area == SheetArea.Cells))
                {
                    object[,] arrayFormula = Excel.GetsArrayFormulas(sheet, baseRow, baseColumn, rowCount, columnCount);
                    if ((arrayFormula != null) && (arrayFormula.Length > 0))
                    {
                        int length = arrayFormula.GetLength(0);
                        for (int k = 0; k < length; k++)
                        {
                            CellRange range = (CellRange)arrayFormula[k, 0];
                            sheet.SetArrayFormula(range.Row, range.Column, range.RowCount, range.ColumnCount, null);
                        }
                    }
                    arrayFormula = cellsInfo.GetArrayFormula();
                    if ((arrayFormula != null) && (arrayFormula.Length > 0))
                    {
                        int num7 = arrayFormula.GetLength(0);
                        for (int m = 0; m < num7; m++)
                        {
                            CellRange range2  = (CellRange)arrayFormula[m, 0];
                            string    formula = (string)((string)arrayFormula[m, 1]);
                            if (formula.StartsWith("{") && formula.EndsWith("}"))
                            {
                                formula = formula.Substring(1, formula.Length - 2);
                            }
                            sheet.SetArrayFormula(range2.Row, range2.Column, range2.RowCount, range2.ColumnCount, formula);
                        }
                    }
                }
            }
            finally
            {
                sheet.ResumeCalcService();
            }
            SheetSpanModel spanModel = null;

            if (area == SheetArea.Cells)
            {
                spanModel = sheet.SpanModel;
            }
            else if (area == SheetArea.ColumnHeader)
            {
                spanModel = sheet.ColumnHeaderSpanModel;
            }
            else if (area == (SheetArea.CornerHeader | SheetArea.RowHeader))
            {
                spanModel = sheet.RowHeaderSpanModel;
            }
            if ((spanModel != null) && !spanModel.IsEmpty())
            {
                List <CellRange> list6      = new List <CellRange>();
                IEnumerator      enumerator = spanModel.GetEnumerator(baseRow, baseColumn, rowCount, columnCount);
                while (enumerator.MoveNext())
                {
                    CellRange current = enumerator.Current as CellRange;
                    if (current != null)
                    {
                        list6.Add(current);
                    }
                }
                foreach (CellRange range4 in list6)
                {
                    spanModel.Remove(range4.Row, range4.Column);
                }
            }
            if (cellsInfo.IsSpanSaved() && (spanModel != null))
            {
                foreach (CellRange range5 in cellsInfo.Spans)
                {
                    spanModel.Add(range5.Row, range5.Column, range5.RowCount, range5.ColumnCount);
                }
            }
        }
Пример #8
0
 public static void SaveRowHeaderInfo(Worksheet sheet, CopyMoveCellsInfo headerCellsInfo, CopyMoveRowsInfo rowsInfo, int baseRow, CopyToOption option)
 {
     if ((option & CopyToOption.All) > ((CopyToOption)0))
     {
         int rowCount    = headerCellsInfo.RowCount;
         int columnCount = headerCellsInfo.ColumnCount;
         for (int i = 0; i < rowCount; i++)
         {
             for (int k = 0; k < columnCount; k++)
             {
                 if ((option & CopyToOption.Value) > ((CopyToOption)0))
                 {
                     headerCellsInfo.SaveValue(i, k, sheet.GetValue(baseRow + i, k, SheetArea.CornerHeader | SheetArea.RowHeader));
                 }
                 if ((option & CopyToOption.Style) > ((CopyToOption)0))
                 {
                     headerCellsInfo.SaveStyle(i, k, GetStyleObject(sheet, baseRow + i, k, SheetArea.CornerHeader | SheetArea.RowHeader));
                 }
                 if ((option & CopyToOption.Tag) > ((CopyToOption)0))
                 {
                     headerCellsInfo.SaveTag(i, k, sheet.GetTag(baseRow + i, k, SheetArea.CornerHeader | SheetArea.RowHeader));
                 }
             }
         }
         if ((option & CopyToOption.Span) > ((CopyToOption)0))
         {
             IEnumerator enumerator = sheet.RowHeaderSpanModel.GetEnumerator(baseRow, 0, rowCount, columnCount);
             while (enumerator.MoveNext())
             {
                 headerCellsInfo.SaveSpan((CellRange)enumerator.Current);
             }
         }
         rowCount = rowsInfo.RowCount;
         for (int j = 0; j < rowCount; j++)
         {
             rowsInfo.SaveHeight(j, sheet.GetRowHeight(baseRow + j));
             rowsInfo.SaveVisible(j, sheet.GetRowVisible(baseRow + j));
             rowsInfo.SaveResizable(j, sheet.GetRowResizable(baseRow + j));
             rowsInfo.SaveTag(j, sheet.GetTag(baseRow + j, -1));
         }
         if ((option & CopyToOption.Style) > ((CopyToOption)0))
         {
             for (int m = 0; m < rowCount; m++)
             {
                 rowsInfo.SaveViewportRowStyle(m, GetStyleObject(sheet, baseRow + m, -1, SheetArea.Cells));
                 rowsInfo.SaveHeaderRowStyle(m, GetStyleObject(sheet, baseRow + m, -1, SheetArea.CornerHeader | SheetArea.RowHeader));
             }
         }
         if ((option & CopyToOption.RangeGroup) > ((CopyToOption)0))
         {
             RangeGroup rowRangeGroup = sheet.RowRangeGroup;
             if ((rowRangeGroup != null) && !rowRangeGroup.IsEmpty())
             {
                 for (int n = 0; n < rowCount; n++)
                 {
                     rowsInfo.SaveRangeGroup(n, rowRangeGroup.Data.GetLevel(baseRow + n), rowRangeGroup.Data.GetCollapsed(baseRow + n));
                 }
             }
         }
     }
 }
Пример #9
0
        public static void SaveColumnHeaderInfo(Worksheet sheet, CopyMoveCellsInfo headerCellsInfo, CopyMoveColumnsInfo columnsInfo, int baseColumn, CopyToOption option)
        {
            int rowCount    = headerCellsInfo.RowCount;
            int columnCount = headerCellsInfo.ColumnCount;

            for (int i = 0; i < rowCount; i++)
            {
                for (int k = 0; k < columnCount; k++)
                {
                    if ((option & CopyToOption.Value) > ((CopyToOption)0))
                    {
                        headerCellsInfo.SaveValue(i, k, sheet.GetValue(i, baseColumn + k, SheetArea.ColumnHeader));
                    }
                    if ((option & CopyToOption.Style) > ((CopyToOption)0))
                    {
                        headerCellsInfo.SaveStyle(i, k, GetStyleObject(sheet, i, baseColumn + k, SheetArea.ColumnHeader));
                    }
                    if ((option & CopyToOption.Tag) > ((CopyToOption)0))
                    {
                        headerCellsInfo.SaveTag(i, k, sheet.GetTag(i, baseColumn + k, SheetArea.ColumnHeader));
                    }
                }
            }
            if ((option & CopyToOption.Value) > ((CopyToOption)0))
            {
                for (int m = 0; m < columnCount; m++)
                {
                    if (sheet.IsColumnBound(baseColumn + m))
                    {
                        columnsInfo.SaveBindingField(m, sheet.GetDataColumnName(baseColumn + m));
                    }
                }
            }
            if ((option & CopyToOption.Span) > ((CopyToOption)0))
            {
                IEnumerator enumerator = sheet.ColumnHeaderSpanModel.GetEnumerator(0, baseColumn, rowCount, columnCount);
                while (enumerator.MoveNext())
                {
                    headerCellsInfo.SaveSpan((CellRange)enumerator.Current);
                }
            }
            columnCount = columnsInfo.ColumnCount;
            for (int j = 0; j < columnCount; j++)
            {
                columnsInfo.SaveWidth(j, sheet.GetColumnWidth(baseColumn + j));
                columnsInfo.SaveVisible(j, sheet.GetColumnVisible(baseColumn + j));
                columnsInfo.SaveResizable(j, sheet.GetColumnResizable(baseColumn + j));
                columnsInfo.SaveTag(j, sheet.GetTag(-1, baseColumn + j));
            }
            if ((option & CopyToOption.Style) > ((CopyToOption)0))
            {
                for (int n = 0; n < columnCount; n++)
                {
                    columnsInfo.SaveViewportColumnStyle(n, GetStyleObject(sheet, -1, baseColumn + n, SheetArea.Cells));
                    columnsInfo.SaveHeaderColumnStyle(n, GetStyleObject(sheet, -1, baseColumn + n, SheetArea.ColumnHeader));
                }
            }
            if ((option & CopyToOption.RangeGroup) > ((CopyToOption)0))
            {
                RangeGroup columnRangeGroup = sheet.ColumnRangeGroup;
                if ((columnRangeGroup != null) && !columnRangeGroup.IsEmpty())
                {
                    for (int num8 = 0; num8 < columnCount; num8++)
                    {
                        columnsInfo.SaveRangeGroup(num8, columnRangeGroup.Data.GetLevel(baseColumn + num8), columnRangeGroup.Data.GetCollapsed(baseColumn + num8));
                    }
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Saves the state for undoing the action.
        /// </summary>
        public void SaveState()
        {
            InitSaveState();
            int baseRow     = (_dragDropExtent.FromRow < 0) ? 0 : _dragDropExtent.FromRow;
            int baseColumn  = (_dragDropExtent.FromColumn < 0) ? 0 : _dragDropExtent.FromColumn;
            int row         = (_dragDropExtent.ToRow < 0) ? 0 : _dragDropExtent.ToRow;
            int num4        = (_dragDropExtent.ToColumn < 0) ? 0 : _dragDropExtent.ToColumn;
            int rowCount    = (_dragDropExtent.FromRow < 0) ? _sheet.RowCount : _dragDropExtent.RowCount;
            int columnCount = (_dragDropExtent.FromColumn < 0) ? _sheet.ColumnCount : _dragDropExtent.ColumnCount;

            if (_insert)
            {
                if (((_dragDropExtent.FromColumn < 0) || (_dragDropExtent.FromRow < 0)) && (((_dragDropExtent.FromColumn < 0) && (_dragDropExtent.FromRow >= 0)) && (!_copy && Excel.HasTable(_sheet, row, -1, 1, -1, true))))
                {
                    CopyMoveCellsInfo headerCellsInfo = new CopyMoveCellsInfo(rowCount, _sheet.RowHeader.ColumnCount);
                    CopyMoveRowsInfo  rowsInfo        = new CopyMoveRowsInfo(rowCount);
                    CopyMoveHelper.SaveRowHeaderInfo(_sheet, headerCellsInfo, rowsInfo, baseRow, _option);
                    _savedFromRowHeaderCells = headerCellsInfo;
                    _savedFromRows           = rowsInfo;
                    CopyMoveCellsInfo cellsInfo = new CopyMoveCellsInfo(rowCount, columnCount);
                    CopyMoveHelper.SaveViewportInfo(_sheet, cellsInfo, baseRow, baseColumn, _option);
                    _savedFromViewportCells = cellsInfo;
                }
            }
            else
            {
                if (_dragDropExtent.FromRow < 0)
                {
                    CopyMoveCellsInfo   info4       = new CopyMoveCellsInfo(_sheet.ColumnHeader.RowCount, columnCount);
                    CopyMoveColumnsInfo columnsInfo = new CopyMoveColumnsInfo(columnCount);
                    CopyMoveHelper.SaveColumnHeaderInfo(_sheet, info4, columnsInfo, num4, _option);
                    _savedToColumnHeaderCells = info4;
                    _savedToColumns           = columnsInfo;
                    if (!_copy)
                    {
                        CopyMoveCellsInfo   info6 = new CopyMoveCellsInfo(_sheet.ColumnHeader.RowCount, columnCount);
                        CopyMoveColumnsInfo info7 = new CopyMoveColumnsInfo(columnCount);
                        CopyMoveHelper.SaveColumnHeaderInfo(_sheet, info6, info7, baseColumn, _option);
                        _savedFromColumnHeaderCells = info6;
                        _savedFromColumns           = info7;
                    }
                }
                if (_dragDropExtent.FromColumn < 0)
                {
                    CopyMoveCellsInfo info8 = new CopyMoveCellsInfo(rowCount, _sheet.RowHeader.ColumnCount);
                    CopyMoveRowsInfo  info9 = new CopyMoveRowsInfo(rowCount);
                    CopyMoveHelper.SaveRowHeaderInfo(_sheet, info8, info9, row, _option);
                    _savedToRowHeaderCells = info8;
                    _savedToRows           = info9;
                    if (!_copy)
                    {
                        CopyMoveCellsInfo info10 = new CopyMoveCellsInfo(rowCount, _sheet.RowHeader.ColumnCount);
                        CopyMoveRowsInfo  info11 = new CopyMoveRowsInfo(rowCount);
                        CopyMoveHelper.SaveRowHeaderInfo(_sheet, info10, info11, baseRow, _option);
                        _savedFromRowHeaderCells = info10;
                        _savedFromRows           = info11;
                    }
                }
                CopyMoveCellsInfo info12 = new CopyMoveCellsInfo(rowCount, columnCount);
                CopyMoveHelper.SaveViewportInfo(_sheet, info12, row, num4, _option);
                _savedToViewportCells = info12;
                if (!_copy)
                {
                    CopyMoveCellsInfo info13 = new CopyMoveCellsInfo(rowCount, columnCount);
                    CopyMoveHelper.SaveViewportInfo(_sheet, info13, baseRow, baseColumn, _option);
                    _savedFromViewportCells = info13;
                    if ((_option & CopyToOption.FloatingObject) > ((CopyToOption)0))
                    {
                        CellRange        range = new CellRange(_dragDropExtent.FromRow, _dragDropExtent.FromColumn, _dragDropExtent.RowCount, _dragDropExtent.ColumnCount);
                        FloatingObject[] floatingObjectsInRange = CopyMoveHelper.GetFloatingObjectsInRange(CopyMoveHelper.AdjustRange(range, _sheet.RowCount, _sheet.ColumnCount), _sheet);
                        _savedFromFloatingObjects = new CopyMoveFloatingObjectsInfo();
                        _savedFromFloatingObjects.SaveFloatingObjects(range, floatingObjectsInRange);
                    }
                }
                if ((_option & CopyToOption.FloatingObject) > ((CopyToOption)0))
                {
                    CellRange        range3          = new CellRange(_dragDropExtent.ToRow, _dragDropExtent.ToColumn, _dragDropExtent.RowCount, _dragDropExtent.ColumnCount);
                    FloatingObject[] floatingObjects = CopyMoveHelper.GetFloatingObjectsInRange(CopyMoveHelper.AdjustRange(range3, _sheet.RowCount, _sheet.ColumnCount), _sheet);
                    _savedToFloatingObjects = new CopyMoveFloatingObjectsInfo();
                    _savedToFloatingObjects.SaveFloatingObjects(range3, floatingObjects);
                }
            }
            _savedAcitveRowViewportIndex    = _sheet.GetActiveRowViewportIndex();
            _savedAcitveColumnViewportIndex = _sheet.GetActiveColumnViewportIndex();
            _savedActiveRow    = _sheet.ActiveRowIndex;
            _savedActiveColumn = _sheet.ActiveColumnIndex;
        }