using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Threading; using System.Xml.Serialization; using CPF.Drawing; using CPF.Input; using CPF.ReoGrid.Actions; using CPF.ReoGrid.CellTypes; using CPF.ReoGrid.Common; using CPF.ReoGrid.Core; using CPF.ReoGrid.Data; using CPF.ReoGrid.DataFormat; using CPF.ReoGrid.Drawing; using CPF.ReoGrid.Events; using CPF.ReoGrid.Formula; using CPF.ReoGrid.Interaction; using CPF.ReoGrid.IO; using CPF.ReoGrid.Main; using CPF.ReoGrid.Outline; using CPF.ReoGrid.Print; using CPF.ReoGrid.Rendering; using CPF.ReoGrid.Utility; using CPF.ReoGrid.Views; using CPF.ReoGrid.XML; namespace CPF.ReoGrid { public sealed class Worksheet : IDisposable { public void SetRangeBorders(string addressOrName, BorderPositions pos, RangeBorderStyle style) { bool flag = RangePosition.IsValidAddress(addressOrName); if (flag) { this.SetRangeBorders(new RangePosition(addressOrName), pos, style); } else { NamedRange refRange; bool flag2 = this.registeredNamedRanges.TryGetValue(addressOrName, out refRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } this.SetRangeBorders(refRange, pos, style); } } public void SetRangeBorders(int row, int col, int rows, int cols, BorderPositions pos, RangeBorderStyle style) { this.SetRangeBorders(new RangePosition(row, col, rows, cols), pos, style); } public void SetRangeBorders(RangePosition range, BorderPositions pos, RangeBorderStyle style) { this.SetRangeBorders(this.FixRange(range), pos, style, true); } internal void SetRangeBorders(RangePosition range, BorderPositions pos, RangeBorderStyle style, bool invalidateWorksheet) { range = this.FixRange(range); int row = range.Row; int col = range.Col; int num = range.EndRow + 1; int num2 = range.EndCol + 1; bool flag = (pos & BorderPositions.Right) == BorderPositions.Right && num2 > this.cols.Count; if (flag) { throw new ArgumentOutOfRangeException("Right side of range out of worksheet."); } bool flag2 = (pos & BorderPositions.Bottom) == BorderPositions.Bottom && num > this.rows.Count; if (flag2) { throw new ArgumentOutOfRangeException("Bottom side of range out of worksheet."); } bool flag3 = (pos & BorderPositions.Left) == BorderPositions.Left; if (flag3) { this.CutBeforeVBorder(row, col); this.SetVBorders(row, col, range.Rows, style, VBorderOwnerPosition.Left); } bool flag4 = (pos & BorderPositions.Right) == BorderPositions.Right; if (flag4) { this.CutBeforeVBorder(row, num2); this.SetVBorders(row, num2, range.Rows, style, VBorderOwnerPosition.Right); } bool flag5 = (pos & BorderPositions.Top) == BorderPositions.Top; if (flag5) { this.CutBeforeHBorder(row, col); this.SetHBorders(row, col, range.Cols, style, HBorderOwnerPosition.Top); } bool flag6 = (pos & BorderPositions.Bottom) == BorderPositions.Bottom; if (flag6) { this.CutBeforeHBorder(num, col); this.SetHBorders(num, col, range.Cols, style, HBorderOwnerPosition.Bottom); } bool flag7 = (pos & BorderPositions.InsideVertical) == BorderPositions.InsideVertical; if (flag7) { for (int i = col + 1; i < num2; i++) { this.CutBeforeVBorder(row, i); this.SetVBorders(row, i, range.Rows, style, VBorderOwnerPosition.All); } } bool flag8 = (pos & BorderPositions.InsideHorizontal) == BorderPositions.InsideHorizontal; if (flag8) { for (int j = row + 1; j < num; j++) { this.CutBeforeHBorder(j, col); this.SetHBorders(j, col, range.Cols, style, HBorderOwnerPosition.All); } } if (invalidateWorksheet) { this.RequestInvalidate(); } bool flag9 = !style.IsEmpty; if (flag9) { EventHandler borderAdded = this.BorderAdded; if (borderAdded != null) { borderAdded(this, new BorderAddedEventArgs(range, pos, style)); } } else { EventHandler borderRemoved = this.BorderRemoved; if (borderRemoved != null) { borderRemoved(this, new BorderRemovedEventArgs(range, pos)); } } } public void RemoveRangeBorders(RangePosition range, BorderPositions pos) { this.SetRangeBorders(range, pos, RangeBorderStyle.Empty); } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler BorderAdded; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler BorderRemoved; public RangeBorderInfoSet GetRangeBorders(int row, int col, int rows, int cols, BorderPositions pos = BorderPositions.All, bool onlyCellsOwn = true) { return this.GetRangeBorders(new RangePosition(row, col, rows, cols), pos, onlyCellsOwn); } public RangeBorderInfoSet GetRangeBorders(string addressOrName, BorderPositions pos = BorderPositions.All, bool onlyCellsOwn = true) { bool flag = RangePosition.IsValidAddress(addressOrName); RangeBorderInfoSet rangeBorders; if (flag) { rangeBorders = this.GetRangeBorders(new RangePosition(addressOrName), pos, onlyCellsOwn); } else { NamedRange refRange = null; bool flag2 = NamedRange.IsValidName(addressOrName) && this.registeredNamedRanges.TryGetValue(addressOrName, out refRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } rangeBorders = this.GetRangeBorders(refRange, pos, onlyCellsOwn); } return rangeBorders; } public RangeBorderInfoSet GetRangeBorders(RangePosition range, BorderPositions pos = BorderPositions.All, bool onlyCellsOwn = true) { RangePosition rangePosition = this.FixRange(range); RangeBorderInfoSet rangeBorderInfoSet = new RangeBorderInfoSet(); bool flag = rangePosition.Rows == 0 || rangePosition.Cols == 0; RangeBorderInfoSet result; if (flag) { result = rangeBorderInfoSet; } else { bool flag2 = pos.Has(BorderPositions.Top); if (flag2) { rangeBorderInfoSet.Top = this.GetGridBorder(rangePosition.Row, rangePosition.Col, BorderPositions.Top, onlyCellsOwn); for (int i = rangePosition.Col + 1; i <= rangePosition.EndCol; i++) { bool flag3 = rangeBorderInfoSet.Top != null; if (flag3) { bool flag4 = this.hBorders[rangePosition.Row, i] == null || (this.hBorders[rangePosition.Row, i].Style != null && !this.hBorders[rangePosition.Row, i].Style.Equals(rangeBorderInfoSet.Top)); if (flag4) { rangeBorderInfoSet.NonUniformPos |= BorderPositions.Top; break; } } else { bool flag5 = this.hBorders[rangePosition.Row, i] != null && this.hBorders[rangePosition.Row, i].Style != null; if (flag5) { rangeBorderInfoSet.NonUniformPos |= BorderPositions.Top; break; } } } } bool flag6 = pos.Has(BorderPositions.Bottom); if (flag6) { rangeBorderInfoSet.Bottom = this.GetGridBorder(rangePosition.EndRow, rangePosition.Col, BorderPositions.Bottom, onlyCellsOwn); bool flag7 = rangeBorderInfoSet.Bottom != null; if (flag7) { for (int j = rangePosition.Col + 1; j <= rangePosition.EndCol; j++) { bool flag8 = this.hBorders[rangePosition.EndRow + 1, j] == null || (this.hBorders[rangePosition.EndRow + 1, j].Style != null && !this.hBorders[rangePosition.EndRow + 1, j].Style.Equals(rangeBorderInfoSet.Bottom)); if (flag8) { rangeBorderInfoSet.NonUniformPos |= BorderPositions.Bottom; break; } } } else { for (int k = rangePosition.Col + 1; k <= rangePosition.EndCol; k++) { bool flag9 = this.hBorders[rangePosition.EndRow + 1, k] != null && this.hBorders[rangePosition.EndRow + 1, k].Style != null; if (flag9) { rangeBorderInfoSet.NonUniformPos |= BorderPositions.Bottom; break; } } } } bool flag10 = pos.Has(BorderPositions.Left); if (flag10) { rangeBorderInfoSet.Left = this.GetGridBorder(rangePosition.Row, rangePosition.Col, BorderPositions.Left, onlyCellsOwn); bool flag11 = rangeBorderInfoSet.Left != null; if (flag11) { for (int l = rangePosition.Row + 1; l < rangePosition.EndRow; l++) { bool flag12 = this.vBorders[l, rangePosition.Col] == null || (this.vBorders[l, rangePosition.Col].Style != null && !this.vBorders[l, rangePosition.Col].Style.Equals(rangeBorderInfoSet.Left)); if (flag12) { rangeBorderInfoSet.NonUniformPos |= BorderPositions.Left; break; } } } else { for (int m = rangePosition.Row + 1; m <= rangePosition.EndRow; m++) { bool flag13 = this.vBorders[m, rangePosition.Col] != null && this.vBorders[m, rangePosition.Col].Style != null; if (flag13) { rangeBorderInfoSet.NonUniformPos |= BorderPositions.Left; break; } } } } bool flag14 = pos.Has(BorderPositions.Right); if (flag14) { rangeBorderInfoSet.Right = this.GetGridBorder(rangePosition.Row, rangePosition.EndCol, BorderPositions.Right, onlyCellsOwn); bool flag15 = rangeBorderInfoSet.Right != null; if (flag15) { for (int n = rangePosition.Row + 1; n < rangePosition.EndRow; n++) { bool flag16 = this.vBorders[n, rangePosition.EndCol + 1] == null || (this.vBorders[n, rangePosition.EndCol + 1].Style != null && !this.vBorders[n, rangePosition.EndCol + 1].Style.Equals(rangeBorderInfoSet.Right)); if (flag16) { rangeBorderInfoSet.NonUniformPos |= BorderPositions.Right; break; } } } else { for (int num = rangePosition.Row + 1; num < rangePosition.EndRow; num++) { bool flag17 = this.vBorders[num, rangePosition.EndCol + 1] != null && this.vBorders[num, rangePosition.EndCol + 1].Style != null; if (flag17) { rangeBorderInfoSet.NonUniformPos |= BorderPositions.Right; break; } } } } bool flag18 = false; bool flag19 = pos.Has(BorderPositions.InsideHorizontal); if (flag19) { int num2 = Math.Min(rangePosition.EndRow, this.hBorders.MaxRow); int num3 = Math.Min(rangePosition.EndCol, this.hBorders.MaxCol); for (int num4 = rangePosition.Row + 1; num4 <= num2; num4++) { int num5 = rangePosition.Col; while (num5 <= num3) { ReoGridHBorder reoGridHBorder = this.hBorders[num4, num5]; bool flag20 = reoGridHBorder != null; if (flag20) { bool flag21 = reoGridHBorder.Span == 0; if (flag21) { num5++; continue; } num5 += reoGridHBorder.Span; bool flag22 = !flag18; if (flag22) { rangeBorderInfoSet.InsideHorizontal = reoGridHBorder.Style; } } else { num5++; bool flag23 = !flag18; if (flag23) { rangeBorderInfoSet.InsideHorizontal = RangeBorderStyle.Empty; } } bool flag24 = flag18; if (flag24) { bool flag25 = (reoGridHBorder != null || !rangeBorderInfoSet.InsideHorizontal.IsEmpty) && (reoGridHBorder == null || rangeBorderInfoSet.InsideHorizontal.IsEmpty || !(reoGridHBorder.Style == rangeBorderInfoSet.InsideHorizontal)); if (flag25) { rangeBorderInfoSet.NonUniformPos |= BorderPositions.InsideHorizontal; num4 = rangePosition.EndRow; break; } } flag18 = true; } } } flag18 = false; bool flag26 = pos.Has(BorderPositions.InsideVertical); if (flag26) { int num6 = Math.Min(rangePosition.EndRow, this.vBorders.MaxRow); int num7 = Math.Min(rangePosition.EndCol, this.vBorders.MaxCol); for (int num8 = rangePosition.Col + 1; num8 <= num7; num8++) { int num9 = rangePosition.Row; while (num9 <= num6) { ReoGridVBorder reoGridVBorder = this.vBorders[num9, num8]; bool flag27 = reoGridVBorder != null; if (flag27) { bool flag28 = reoGridVBorder.Span == 0; if (flag28) { num9++; continue; } num9 += reoGridVBorder.Span; bool flag29 = !flag18; if (flag29) { rangeBorderInfoSet.InsideVertical = reoGridVBorder.Style; } } else { num9++; bool flag30 = !flag18; if (flag30) { rangeBorderInfoSet.InsideVertical = RangeBorderStyle.Empty; } } bool flag31 = flag18; if (flag31) { bool flag32 = (reoGridVBorder != null || !rangeBorderInfoSet.InsideVertical.IsEmpty) && (reoGridVBorder == null || rangeBorderInfoSet.InsideVertical.IsEmpty || !(reoGridVBorder.Style == rangeBorderInfoSet.InsideVertical)); if (flag32) { rangeBorderInfoSet.NonUniformPos |= BorderPositions.InsideVertical; num8 = rangePosition.EndCol; break; } } flag18 = true; } } } result = rangeBorderInfoSet; } return result; } internal RangeBorderStyle GetGridBorder(int row, int col, BorderPositions pos, bool onlyGridOwn) { bool flag = pos == BorderPositions.Top && this.hBorders[row, col] != null && (!onlyGridOwn || (this.hBorders[row, col].Pos & HBorderOwnerPosition.Top) == HBorderOwnerPosition.Top); RangeBorderStyle result; if (flag) { result = this.hBorders[row, col].Style; } else { bool flag2 = pos == BorderPositions.Bottom && this.hBorders[row + 1, col] != null && (!onlyGridOwn || (this.hBorders[row + 1, col].Pos & HBorderOwnerPosition.Bottom) == HBorderOwnerPosition.Bottom); if (flag2) { result = this.hBorders[row + 1, col].Style; } else { bool flag3 = pos == BorderPositions.Left && this.vBorders[row, col] != null && (!onlyGridOwn || (this.vBorders[row, col].Pos & VBorderOwnerPosition.Left) == VBorderOwnerPosition.Left); if (flag3) { result = this.vBorders[row, col].Style; } else { bool flag4 = pos == BorderPositions.Right && this.vBorders[row, col + 1] != null && (!onlyGridOwn || (this.vBorders[row, col + 1].Pos & VBorderOwnerPosition.Right) == VBorderOwnerPosition.Right); if (flag4) { result = this.vBorders[row, col + 1].Style; } else { result = RangeBorderStyle.Empty; } } } } return result; } public void IterateBorders(RowOrColumn scanDirections, RangePosition range, Func iterator) { range = this.FixRange(range); bool flag = (scanDirections & RowOrColumn.Row) == RowOrColumn.Row; if (flag) { for (int i = range.Row; i <= range.EndRow; i++) { for (int j = range.Col; j <= range.EndCol; j++) { ReoGridHBorder reoGridHBorder = this.hBorders[i, j]; bool flag2 = reoGridHBorder != null; if (flag2) { bool flag3 = reoGridHBorder.Span > 0; if (flag3) { bool flag4 = !iterator(i, j, reoGridHBorder.Span, reoGridHBorder.Style); if (flag4) { goto IL_B7; } j += reoGridHBorder.Span; continue; } } } } } IL_B7: bool flag5 = (scanDirections & RowOrColumn.Column) == RowOrColumn.Column; if (flag5) { for (int k = range.Col; k <= range.EndCol; k++) { for (int l = range.Row; l <= range.EndRow; l++) { ReoGridVBorder reoGridVBorder = this.vBorders[l, k]; bool flag6 = reoGridVBorder != null; if (flag6) { bool flag7 = reoGridVBorder.Span > 0; if (flag7) { bool flag8 = !iterator(l, k, reoGridVBorder.Span, reoGridVBorder.Style); if (flag8) { return; } l += reoGridVBorder.Span; continue; } } } } } } internal ReoGridHBorder GetHBorder(int row, int col) { ReoGridHBorder reoGridHBorder = this.hBorders[row, col]; bool flag = reoGridHBorder == null; if (flag) { reoGridHBorder = (this.hBorders[row, col] = new ReoGridHBorder()); } return reoGridHBorder; } internal ReoGridVBorder GetVBorder(int row, int col) { ReoGridVBorder reoGridVBorder = this.vBorders[row, col]; bool flag = reoGridVBorder == null; if (flag) { reoGridVBorder = (this.vBorders[row, col] = new ReoGridVBorder()); } return reoGridVBorder; } internal ReoGridHBorder RetrieveHBorder(int row, int col) { return this.hBorders[row, col]; } internal ReoGridVBorder RetrieveVBorder(int row, int col) { return this.vBorders[row, col]; } internal ReoGridHBorder GetValidHBorderByPos(int row, int col, HBorderOwnerPosition pos) { ReoGridHBorder reoGridHBorder = this.hBorders[row, col]; bool flag = reoGridHBorder == null || reoGridHBorder.Span == 0; ReoGridHBorder result; if (flag) { result = null; } else { bool flag2 = (reoGridHBorder.Pos & pos) == pos; if (flag2) { result = reoGridHBorder; } else { result = null; } } return result; } internal ReoGridVBorder GetValidVBorderByPos(int row, int col, VBorderOwnerPosition pos) { ReoGridVBorder reoGridVBorder = this.vBorders[row, col]; bool flag = reoGridVBorder == null || reoGridVBorder.Span == 0; ReoGridVBorder result; if (flag) { result = null; } else { bool flag2 = (reoGridVBorder.Pos & pos) == pos; if (flag2) { result = reoGridVBorder; } else { result = null; } } return result; } private void CutBeforeHBorder(int row, int col) { bool flag = col < 1; if (!flag) { ReoGridHBorder reoGridHBorder = this.hBorders[row, col - 1]; bool flag2 = reoGridHBorder != null && reoGridHBorder.Span > 1; if (flag2) { int i = col - 1; int span = reoGridHBorder.Span; while (i >= 0) { bool flag3 = this.hBorders[row, i] == null || this.hBorders[row, i].Span <= 1; if (flag3) { break; } this.hBorders[row, i].Span -= span - 1; i--; } } } } private int FindSameHBorderLeft(int row, int col, RangeBorderStyle borderStyle) { bool flag = col <= 0; int result; if (flag) { result = col; } else { for (int i = col - 1; i >= 0; i--) { ReoGridHBorder reoGridHBorder = this.hBorders[row, i]; bool flag2 = reoGridHBorder == null; if (flag2) { return i + 1; } bool flag3 = reoGridHBorder.Style == null && borderStyle != null; if (flag3) { return i + 1; } bool flag4 = reoGridHBorder.Style != null && !reoGridHBorder.Style.Equals(borderStyle); if (flag4) { return i + 1; } } result = 0; } return result; } private int FindSameHBorderRight(int row, int col, RangeBorderStyle borderStyle) { bool flag = col > this.cols.Count - 1; int result; if (flag) { result = col; } else { for (int i = col + 1; i < this.cols.Count; i++) { ReoGridHBorder reoGridHBorder = this.hBorders[row, i]; bool flag2 = reoGridHBorder == null; if (flag2) { return i - 1; } bool flag3 = reoGridHBorder == null && borderStyle != null; if (flag3) { return i - 1; } bool flag4 = !reoGridHBorder.Style.Equals(borderStyle); if (flag4) { return i - 1; } } result = this.cols.Count - 1; } return result; } private void FillHBorders(int row, int col, int cols, RangeBorderStyle borderStyle, HBorderOwnerPosition pos) { int num = col + cols; for (int i = col; i < num; i++) { this.SetHBorder(row, i, num - i, borderStyle, pos); } } private void SetHBorders(int row, int col, int cols, RangeBorderStyle borderStyle, HBorderOwnerPosition pos) { int num = col; int num2 = col + cols - 1; bool flag = borderStyle != null; if (flag) { num = this.FindSameHBorderLeft(row, col, borderStyle); num2 = this.FindSameHBorderRight(row, col + cols - 1, borderStyle); cols = num2 - num + 1; } int num3 = num + cols; int num4 = num3; int num5 = -1; for (int i = num; i < num3; i++) { bool flag2 = row > 0; if (flag2) { Cell cell = this.cells[row - 1, i]; Cell cell2 = this.cells[row, i]; bool flag3 = cell != null && cell2 != null && !cell.MergeEndPos.IsEmpty && CellPosition.Equals(cell.MergeStartPos, cell2.MergeStartPos); if (flag3) { num4 = i; num5 = cell2.MergeEndPos.Col + 1; break; } } } this.FillHBorders(row, num, num4 - num, borderStyle, pos); bool flag4 = num5 != -1; if (flag4) { this.SetHBorders(row, num5, num3 - num5, borderStyle, pos); } } private void SetHBorder(int row, int col, int colspan, RangeBorderStyle borderStyle, HBorderOwnerPosition pos) { bool flag = borderStyle == null; if (flag) { this.hBorders[row, col] = null; } else { ReoGridHBorder hborder = this.GetHBorder(row, col); hborder.Span = colspan; hborder.Style = borderStyle; hborder.Pos |= pos; } } private int FindSameVBorderTop(int row, int col, RangeBorderStyle borderStyle) { bool flag = row <= 0; int result; if (flag) { result = row; } else { for (int i = row - 1; i >= 0; i--) { ReoGridVBorder reoGridVBorder = this.vBorders[i, col]; bool flag2 = reoGridVBorder == null; if (flag2) { return i + 1; } bool flag3 = reoGridVBorder.Style == null && borderStyle != null; if (flag3) { return i + 1; } bool flag4 = reoGridVBorder.Style != null && !reoGridVBorder.Style.Equals(borderStyle); if (flag4) { return i + 1; } } result = 0; } return result; } private int FindSameVBorderBottom(int row, int col, RangeBorderStyle borderStyle) { bool flag = row > this.rows.Count - 1; int result; if (flag) { result = row; } else { for (int i = row + 1; i < this.rows.Count; i++) { ReoGridVBorder reoGridVBorder = this.vBorders[i, col]; bool flag2 = reoGridVBorder == null; if (flag2) { return i - 1; } bool flag3 = reoGridVBorder.Style == null && borderStyle != null; if (flag3) { return i - 1; } bool flag4 = !reoGridVBorder.Style.Equals(borderStyle); if (flag4) { return i - 1; } } result = this.rows.Count - 1; } return result; } private void FillVBorders(int row, int col, int rows, RangeBorderStyle borderStyle, VBorderOwnerPosition pos) { int num = row + rows; for (int i = row; i < num; i++) { this.SetVBorder(i, col, num - i, borderStyle, pos); } } private void CutBeforeVBorder(int row, int col) { bool flag = row < 1; if (!flag) { ReoGridVBorder reoGridVBorder = this.vBorders[row - 1, col]; bool flag2 = reoGridVBorder != null && reoGridVBorder.Span > 1; if (flag2) { int i = row - 1; int span = reoGridVBorder.Span; while (i >= 0) { bool flag3 = this.vBorders[i, col] == null || this.vBorders[i, col].Span <= 1; if (flag3) { break; } this.vBorders[i, col].Span -= span - 1; i--; } } } } private void SetVBorders(int row, int col, int rows, RangeBorderStyle borderStyle, VBorderOwnerPosition pos) { int num = row; int num2 = row + rows - 1; bool flag = borderStyle != null; if (flag) { num = this.FindSameVBorderTop(row, col, borderStyle); num2 = this.FindSameVBorderBottom(row + rows - 1, col, borderStyle); rows = num2 - num + 1; } int num3 = num + rows; int num4 = num3; int num5 = -1; for (int i = num; i < num3; i++) { bool flag2 = col > 0; if (flag2) { Cell cell = this.cells[i, col - 1]; Cell cell2 = this.cells[i, col]; bool flag3 = cell != null && cell2 != null && !cell.MergeStartPos.IsEmpty && CellPosition.Equals(cell.MergeStartPos, cell2.MergeStartPos); if (flag3) { num4 = i; num5 = cell2.MergeEndPos.Row + 1; break; } } } this.FillVBorders(num, col, num4 - num, borderStyle, pos); bool flag4 = num5 != -1; if (flag4) { this.SetVBorders(num5, col, num3 - num5, borderStyle, pos); } } private void SetVBorder(int row, int col, int rowspan, RangeBorderStyle borderStyle, VBorderOwnerPosition pos) { bool flag = borderStyle == null; if (flag) { this.vBorders[row, col] = null; } else { ReoGridVBorder vborder = this.GetVBorder(row, col); vborder.Span = rowspan; vborder.Style = borderStyle; vborder.Pos |= pos; } } public void SetCellData(string addressOrName, object data) { bool flag = CellPosition.IsValidAddress(addressOrName); if (flag) { this.SetCellData(new CellPosition(addressOrName), data); } else { NamedRange namedRange; bool flag2 = this.registeredNamedRanges.TryGetValue(addressOrName, out namedRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } this.SetCellData(namedRange.StartPos, data); } } public void SetCellData(CellPosition pos, object data) { this.SetCellData(pos.Row, pos.Col, data); } public void SetCellData(int row, int col, object data) { bool flag = row < 0 || row > this.rows.Count - 1; if (flag) { throw new ArgumentOutOfRangeException("row", "Number of row is out of the maximum rows, use either AppendRows or Resize to expend this worksheet."); } bool flag2 = col < 0 || col > this.cols.Count - 1; if (flag2) { throw new ArgumentOutOfRangeException("col", "Number of column is out of maximum columns, use either AppendCols or Resize to expend this worksheet."); } bool flag3 = data is Array; if (flag3) { Array array = (Array)data; bool flag4 = array.Rank == 1; if (flag4) { for (int i = col; i < Math.Min(col + array.Length, this.cols.Count); i++) { this.SetCellData(row, i, array.GetValue(i - col)); } } else { bool flag5 = array.Rank == 2; if (!flag5) { throw new ArgumentException("Array with more than 2 ranks is not supported."); } int length = array.GetLength(0); int length2 = array.GetLength(1); this.SetRangeData(new RangePosition(row, col, length, length2), array); } } else { bool flag6 = data is IEnumerable; if (flag6) { IEnumerable enumerable = (IEnumerable)data; int num = col; foreach (object data2 in enumerable) { this.SetCellData(row, num, data2); num++; bool flag7 = num >= this.cols.Count; if (flag7) { break; } } } else { bool flag8 = data is PartialGrid; if (flag8) { PartialGrid partialGrid = (PartialGrid)data; RangePosition toRange = new RangePosition(row, col, partialGrid.Rows, partialGrid.Columns); this.SetPartialGrid(toRange, partialGrid); } else { bool flag9 = data is DataTable; if (flag9) { DataTable dataTable = (DataTable)data; this.SetRangeData(new RangePosition(row, col, dataTable.Rows.Count, dataTable.Columns.Count), dataTable); } else { Cell cell = this.cells[row, col]; bool flag10 = (data != null || cell != null) && (cell == null || cell.IsValidCell); if (flag10) { this.SetSingleCellData(this.CreateAndGetCell(row, col), data); } } } } } } internal void SetSingleCellData(Cell cell, object data) { bool flag = data is ICellBody; if (flag) { this.SetCellBody(cell, (ICellBody)data); data = cell.InnerData; } bool flag2 = data is string || data is StringBuilder; if (flag2) { string text = (data is string) ? ((string)data) : Convert.ToString(data); bool flag3 = text.Length > 1; if (flag3) { bool flag4 = text[0] == '\''; if (flag4) { this.ClearCellReferenceList(cell); this.RemoveCellTraceDependents(cell); this.RemoveCellTracePrecedents(cell); cell.formulaStatus = FormulaStatus.Normal; cell.InnerData = data; cell.InnerDisplay = text.Substring(1); this.AfterCellDataUpdate(cell, null); return; } bool flag5 = text[0] == '='; if (flag5) { this.SetCellFormula(cell, text.Substring(1)); try { this.RecalcCell(cell, null); } catch (Exception ex) { this.NotifyExceptionHappen(ex); } return; } } } bool flag6 = this.formulaRanges.Count > 0; if (flag6) { this.ClearCellReferenceList(cell); } cell.InnerFormula = null; cell.formulaStatus = FormulaStatus.Normal; this.UpdateCellData(cell, data, null); } internal void UpdateCellData(Cell cell, object data, Stack> dirtyCellStack = null) { bool flag = cell.body != null; if (flag) { data = cell.body.OnSetData(data); } cell.InnerData = data; bool flag2 = this.HasSettings(WorksheetSettings.Edit_AutoFormatCell); if (flag2) { DataFormatterManager.Instance.FormatCell(cell); } else { cell.InnerDisplay = Convert.ToString(data); } this.AfterCellDataUpdate(cell, dirtyCellStack); } private void AfterCellDataUpdate(Cell cell, Stack> dirtyCellStack = null) { bool flag = (this.settings & WorksheetSettings.Formula_AutoUpdateReferenceCell) == WorksheetSettings.Formula_AutoUpdateReferenceCell; if (flag) { this.UpdateReferencedFormulaCells(cell, dirtyCellStack); } bool flag2 = cell.Data is RichText; if (flag2) { RichText richText = (RichText)cell.Data; richText.SuspendUpdateText(); richText.Size = cell.Bounds.Size; richText.TextWrap = cell.InnerStyle.TextWrapMode; richText.ResumeUpdateText(); richText.UpdateText(); } else { cell.FontDirty = true; } bool flag3 = this.controlAdapter != null && !this.viewDirty && !this.suspendDataChangedEvent; if (flag3) { this.RequestInvalidate(); } bool flag4 = !this.suspendDataChangedEvent; if (flag4) { ColumnHeader columnHeader = this.cols[cell.Column]; bool flag5 = columnHeader.Body != null; if (flag5) { columnHeader.Body.OnDataChange(cell.Row, cell.Row); } this.RaiseCellDataChangedEvent(cell); } } public void SetCellBody(int row, int col, ICellBody body) { bool flag = row < 0; if (flag) { throw new ArgumentOutOfRangeException("row"); } bool flag2 = row >= this.cells.RowCapacity; if (flag2) { throw new ArgumentOutOfRangeException("row"); } bool flag3 = col < 0; if (flag3) { throw new ArgumentOutOfRangeException("col"); } bool flag4 = col >= this.cells.ColCapacity; if (flag4) { throw new ArgumentOutOfRangeException("col"); } Cell cell = this.cells[row, col]; bool flag5 = cell == null; if (flag5) { bool flag6 = body == null; if (flag6) { return; } cell = this.CreateCell(row, col, true); } this.SetCellBody(cell, body); } public void SetCellBody(CellPosition pos, ICellBody body) { pos = this.FixPos(pos); this.SetCellBody(pos.Row, pos.Col, body); } public void SetCellBody(string address, ICellBody body) { bool flag = !CellPosition.IsValidAddress(address); if (flag) { throw new InvalidAddressException(address); } this.SetCellBody(new CellPosition(address), body); } internal void SetCellBody(Cell cell, ICellBody body) { cell.Body = body; this.RequestInvalidate(); } public void RemoveCellBody(CellPosition pos) { this.RemoveCellBody(pos.Row, pos.Col); } public void RemoveCellBody(int row, int col) { Cell cell = this.cells[row, col]; bool flag = cell != null; if (flag) { cell.body = null; this.RequestInvalidate(); } } public object GetCellData(string addressOrName) { bool flag = CellPosition.IsValidAddress(addressOrName); object cellData; if (flag) { cellData = this.GetCellData(new CellPosition(addressOrName)); } else { NamedRange namedRange; bool flag2 = this.registeredNamedRanges.TryGetValue(addressOrName, out namedRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } cellData = this.GetCellData(namedRange.StartPos); } return cellData; } public object GetCellData(CellPosition pos) { return this.GetCellData(pos.Row, pos.Col); } public object GetCellData(int row, int col) { bool flag = row < 0 || row >= this.rows.Count; object result; if (flag) { result = null; } else { bool flag2 = col < 0 || col >= this.cols.Count; if (flag2) { result = null; } else { Cell cell = this.cells[row, col]; result = ((cell == null) ? null : cell.InnerData); } } return result; } public T GetCellData(string addressOrName) { bool flag = CellPosition.IsValidAddress(addressOrName); T cellData; if (flag) { cellData = this.GetCellData(new CellPosition(addressOrName)); } else { NamedRange namedRange; bool flag2 = this.registeredNamedRanges.TryGetValue(addressOrName, out namedRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } cellData = this.GetCellData(namedRange.StartPos); } return cellData; } public T GetCellData(CellPosition pos) { return CellUtility.ConvertData(this.GetCellData(pos)); } public T GetCellData(int row, int col) { return CellUtility.ConvertData(this.GetCellData(row, col)); } public bool TryGetNumberData(int row, int col, out double val) { Cell cell = this.cells[row, col]; bool flag = cell == null; bool result; if (flag) { val = 0.0; result = false; } else { result = CellUtility.TryGetNumberData(cell.Data, out val); } return result; } public string GetCellText(string address) { bool flag = CellPosition.IsValidAddress(address); string cellText; if (flag) { cellText = this.GetCellText(new CellPosition(address)); } else { bool flag2 = RangePosition.IsValidAddress(address); if (flag2) { cellText = this.GetCellText(new RangePosition(address).StartPos); } else { NamedRange namedRange = null; bool flag3 = NamedRange.IsValidName(address) && this.TryGetNamedRange(address, out namedRange); if (!flag3) { throw new InvalidAddressException(address); } cellText = this.GetCellText(namedRange.StartPos); } } return cellText; } public string GetCellText(CellPosition pos) { return this.GetCellText(pos.Row, pos.Col); } public string GetCellText(int row, int col) { Cell cell = this.cells[row, col]; bool flag = cell == null; string result; if (flag) { result = string.Empty; } else { result = (string.IsNullOrEmpty(cell.DisplayText) ? string.Empty : cell.DisplayText); } return result; } public void SuspendDataChangedEvents() { this.suspendDataChangedEvent = true; } public void ResumeDataChangedEvents() { this.suspendDataChangedEvent = false; this.RequestInvalidate(); } internal void RaiseCellDataChangedEvent(Cell cell) { bool flag = this.CellDataChanged != null; if (flag) { this.CellDataChanged(this, new CellEventArgs(cell)); } } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler CellDataChanged; public string StringifyRange(string addressOrName) { bool flag = RangePosition.IsValidAddress(addressOrName); string result; if (flag) { result = this.StringifyRange(new RangePosition(addressOrName)); } else { NamedRange refRange; bool flag2 = this.registeredNamedRanges.TryGetValue(addressOrName, out refRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } result = this.StringifyRange(refRange); } return result; } public string StringifyRange(RangePosition range) { int endRow = range.EndRow; int endCol = range.EndCol; StringBuilder stringBuilder = new StringBuilder(); bool flag = true; for (int i = range.Row; i <= endRow; i++) { bool flag2 = flag; if (flag2) { flag = false; } else { stringBuilder.Append('\n'); } bool flag3 = true; for (int j = range.Col; j <= endCol; j++) { bool flag4 = flag3; if (flag4) { flag3 = false; } else { stringBuilder.Append('\t'); } Cell cell = this.cells[i, j]; bool flag5 = cell != null; if (flag5) { string text = cell.DisplayText; bool flag6 = !string.IsNullOrEmpty(text); if (flag6) { bool flag7 = text.Contains('\n'); if (flag7) { text = string.Format("\"{0}\"", text); } stringBuilder.Append(text); } } } } return stringBuilder.ToString(); } public RangePosition PasteFromString(string address, string content) { bool flag = !CellPosition.IsValidAddress(address); if (flag) { throw new InvalidAddressException(address); } return this.PasteFromString(new CellPosition(address), content); } public RangePosition PasteFromString(CellPosition startPos, string content) { object[,] array = RGUtility.ParseTabbedString(content); int length = array.GetLength(0); int length2 = array.GetLength(1); RangePosition rangePosition = new RangePosition(startPos.Row, startPos.Col, length, length2); this.SetRangeData(rangePosition, array); return rangePosition; } public bool Copy() { bool isEditing = this.IsEditing; if (isEditing) { this.controlAdapter.EditControlCopy(); } else { this.controlAdapter.ChangeCursor(CursorStyle.Busy); try { bool flag = this.BeforeCopy != null; if (flag) { BeforeRangeOperationEventArgs beforeRangeOperationEventArgs = new BeforeRangeOperationEventArgs(this.selectionRange); this.BeforeCopy(this, beforeRangeOperationEventArgs); bool isCancelled = beforeRangeOperationEventArgs.IsCancelled; if (isCancelled) { return false; } } this.currentCopingRange = this.selectionRange; string text = this.StringifyRange(this.currentCopingRange); bool flag2 = !string.IsNullOrEmpty(text); if (flag2) { Clipboard.SetData(new ValueTuple[] { new ValueTuple(CPF.Input.DataFormat.Text, text) }); } bool flag3 = this.AfterCopy != null; if (flag3) { this.AfterCopy(this, new RangeEventArgs(this.selectionRange)); } } catch (Exception ex) { this.NotifyExceptionHappen(ex); return false; } finally { this.controlAdapter.ChangeCursor(CursorStyle.PlatformDefault); } } return true; } public bool Paste() { bool isEditing = this.IsEditing; if (isEditing) { this.controlAdapter.EditControlPaste(); } else { bool flag = this.HasSettings(WorksheetSettings.Edit_Readonly) || this.selectionRange.IsEmpty; if (flag) { return false; } try { this.controlAdapter.ChangeCursor(CursorStyle.Busy); PartialGrid partialGrid = null; string text = null; bool flag2 = Clipboard.Contains(CPF.Input.DataFormat.Text); if (flag2) { text = (string)Clipboard.GetData(CPF.Input.DataFormat.Text); } bool flag3 = partialGrid != null; if (flag3) { int startRow = this.selectionRange.Row; int startCol = this.selectionRange.Col; int num = partialGrid.Rows; int columns = partialGrid.Columns; int num2 = 1; int num3 = 1; bool flag4 = this.selectionRange.Rows % partialGrid.Rows == 0; if (flag4) { num = this.selectionRange.Rows; num2 = this.selectionRange.Rows / partialGrid.Rows; } bool flag5 = this.selectionRange.Cols % partialGrid.Columns == 0; if (flag5) { columns = this.selectionRange.Cols; num3 = this.selectionRange.Cols / partialGrid.Columns; } RangePosition range = new RangePosition(startRow, startCol, num, columns); bool flag6 = !this.RaiseBeforePasteEvent(range); if (flag6) { return false; } bool flag7 = range.EndRow >= this.rows.Count || range.EndCol >= this.cols.Count; if (flag7) { return false; } bool flag8 = this.CheckRangeReadonly(range); if (flag8) { this.NotifyExceptionHappen(new OperationOnReadonlyCellException("specified range contains readonly cell")); return false; } bool flag9 = false; bool flag10 = partialGrid.Cells != null; if (flag10) { try { int num4; int rr; for (rr = 0; rr < num2; rr = num4 + 1) { int cc; for (cc = 0; cc < num3; cc = num4 + 1) { partialGrid.Cells.Iterate(delegate(int row, int col, Cell cell) { bool isMergedCell = cell.IsMergedCell; if (isMergedCell) { for (int i = startRow; i < cell.MergeEndPos.Row - cell.InternalRow + startRow + 1; i++) { for (int j = startCol; j < cell.MergeEndPos.Col - cell.InternalCol + startCol + 1; j++) { int row2 = i + rr * partialGrid.Rows; int col2 = j + cc * partialGrid.Columns; Cell cell2 = this.cells[row2, col2]; bool flag18 = cell2 != null; if (flag18) { bool flag19 = (cell2.Rowspan == 0 && cell2.Colspan == 0) || cell2.IsMergedCell; if (flag19) { throw new RangeIntersectionException(this.selectionRange); } bool isReadOnly = cell2.IsReadOnly; if (isReadOnly) { throw new CellDataReadonlyException(cell.InternalPos); } } } } } return (int)Math.Min(cell.Colspan, (short)1); }); num4 = cc; } num4 = rr; } } catch (Exception ex) { flag9 = true; bool flag11 = this.OnPasteError != null; if (flag11) { this.OnPasteError(this, new RangeOperationErrorEventArgs(this.selectionRange, ex)); } } } bool flag12 = !flag9; if (flag12) { this.DoAction(new SetPartialGridAction(new RangePosition(startRow, startCol, num, columns), partialGrid)); } } else { bool flag13 = !string.IsNullOrEmpty(text); if (flag13) { object[,] array = RGUtility.ParseTabbedString(text); int num5 = Math.Max(this.selectionRange.Rows, array.GetLength(0)); int num6 = Math.Max(this.selectionRange.Cols, array.GetLength(1)); RangePosition range2 = new RangePosition(this.selectionRange.Row, this.selectionRange.Col, num5, num6); bool flag14 = !this.RaiseBeforePasteEvent(range2); if (flag14) { return false; } bool flag15 = this.controlAdapter != null; if (flag15) { IActionControl actionControl = this.controlAdapter.ControlInstance as IActionControl; bool flag16 = actionControl != null; if (flag16) { actionControl.DoAction(this, new SetRangeDataAction(range2, array)); } } } } } catch (Exception ex2) { this.NotifyExceptionHappen(ex2); } finally { this.controlAdapter.ChangeCursor(CursorStyle.Selection); this.RequestInvalidate(); } bool flag17 = this.AfterPaste != null; if (flag17) { this.AfterPaste(this, new RangeEventArgs(this.selectionRange)); } } return true; } private bool RaiseBeforePasteEvent(RangePosition range) { bool flag = this.BeforePaste != null; if (flag) { BeforeRangeOperationEventArgs beforeRangeOperationEventArgs = new BeforeRangeOperationEventArgs(range); this.BeforePaste(this, beforeRangeOperationEventArgs); bool isCancelled = beforeRangeOperationEventArgs.IsCancelled; if (isCancelled) { return false; } } return true; } public bool Cut(bool byAction = true) { bool isEditing = this.IsEditing; if (isEditing) { this.controlAdapter.EditControlCut(); } else { bool flag = !this.Copy(); if (flag) { return false; } bool flag2 = this.BeforeCut != null; if (flag2) { BeforeRangeOperationEventArgs beforeRangeOperationEventArgs = new BeforeRangeOperationEventArgs(this.selectionRange); this.BeforeCut(this, beforeRangeOperationEventArgs); bool isCancelled = beforeRangeOperationEventArgs.IsCancelled; if (isCancelled) { return false; } } bool flag3 = !this.HasSettings(WorksheetSettings.Edit_Readonly); if (flag3) { } bool flag4 = this.AfterCut != null; if (flag4) { this.AfterCut(this, new RangeEventArgs(this.selectionRange)); } } return true; } public bool CanCopy() { return true; } public bool CanCut() { return true; } public bool CanPaste() { return true; } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler BeforePaste; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler AfterPaste; [Obsolete("use ReoGridControl.ErrorHappened instead")] //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler OnPasteError; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler BeforeCopy; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler AfterCopy; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler BeforeCut; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler AfterCut; internal bool TryGetCellComment(Cell cell, out CellComment comment) { bool flag = this.cellComments != null; bool result; if (flag) { result = this.cellComments.TryGetValue(cell, out comment); } else { comment = null; result = false; } return result; } internal void AddCellCommentIfNotExist(Cell cell) { bool flag = this.cellComments == null; if (flag) { this.cellComments = new Dictionary(); } bool flag2 = !this.cellComments.ContainsKey(cell); if (flag2) { this.cellComments[cell] = new CellComment(cell); } } internal void RemoveCellComment(Cell cell) { bool flag = this.cellComments != null; if (flag) { this.cellComments.Remove(cell); this.visibleCellComments.Remove(cell); } } public void LoadCSV(string path) { this.LoadCSV(path, RangePosition.EntireRange); } public void LoadCSV(string path, RangePosition targetRange) { this.LoadCSV(path, Encoding.Default, targetRange); } public void LoadCSV(string path, Encoding encoding) { this.LoadCSV(path, encoding, RangePosition.EntireRange); } public void LoadCSV(string path, Encoding encoding, RangePosition targetRange) { using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { this.LoadCSV(fileStream, encoding, targetRange); } } public void LoadCSV(Stream s) { this.LoadCSV(s, Encoding.Default); } public void LoadCSV(Stream s, RangePosition targetRange) { this.LoadCSV(s, Encoding.Default, targetRange); } public void LoadCSV(Stream s, Encoding encoding) { this.LoadCSV(s, encoding, RangePosition.EntireRange); } public void LoadCSV(Stream s, Encoding encoding, RangePosition targetRange) { this.LoadCSV(s, encoding, targetRange, targetRange.IsEntire, 256); } public void LoadCSV(Stream s, Encoding encoding, RangePosition targetRange, bool autoSpread, int bufferLines) { IControlAdapter controlAdapter = this.controlAdapter; if (controlAdapter != null) { controlAdapter.ChangeCursor(CursorStyle.Busy); } try { CSVFileFormatProvider csvfileFormatProvider = new CSVFileFormatProvider(); CSVFormatArgument arg = new CSVFormatArgument { AutoSpread = autoSpread, BufferLines = bufferLines, TargetRange = targetRange }; this.Clear(); csvfileFormatProvider.Load(this.workbook, s, encoding, arg); } finally { IControlAdapter controlAdapter2 = this.controlAdapter; if (controlAdapter2 != null) { controlAdapter2.ChangeCursor(CursorStyle.PlatformDefault); } } } public void ExportAsCSV(string path, int startRow = 0, Encoding encoding = null) { this.ExportAsCSV(path, new RangePosition(startRow, 0, -1, -1), encoding); } public void ExportAsCSV(string path, string addressOrName, Encoding encoding = null) { bool flag = RangePosition.IsValidAddress(addressOrName); if (flag) { this.ExportAsCSV(path, new RangePosition(addressOrName), encoding); } else { NamedRange refRange; bool flag2 = this.TryGetNamedRange(addressOrName, out refRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } this.ExportAsCSV(path, refRange, encoding); } } public void ExportAsCSV(string path, RangePosition range, Encoding encoding = null) { using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write)) { this.ExportAsCSV(fileStream, range, encoding); } } public void ExportAsCSV(Stream s, int startRow = 0, Encoding encoding = null) { this.ExportAsCSV(s, new RangePosition(startRow, 0, -1, -1), encoding); } public void ExportAsCSV(Stream s, string addressOrName, Encoding encoding = null) { bool flag = RangePosition.IsValidAddress(addressOrName); if (flag) { this.ExportAsCSV(s, new RangePosition(addressOrName), encoding); } else { NamedRange refRange; bool flag2 = this.TryGetNamedRange(addressOrName, out refRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } this.ExportAsCSV(s, refRange, encoding); } } public void ExportAsCSV(Stream s, RangePosition range, Encoding encoding = null) { range = this.FixRange(range); int num = Math.Min(range.EndRow, this.MaxContentRow); int num2 = Math.Min(range.EndCol, this.MaxContentCol); bool flag = encoding == null; if (flag) { encoding = Encoding.Default; } using (StreamWriter streamWriter = new StreamWriter(s, encoding)) { StringBuilder stringBuilder = new StringBuilder(); for (int i = range.Row; i <= num; i++) { bool flag2 = stringBuilder.Length > 0; if (flag2) { streamWriter.WriteLine(stringBuilder.ToString()); stringBuilder.Length = 0; } int j = range.Col; while (j <= num2) { bool flag3 = stringBuilder.Length > 0; if (flag3) { stringBuilder.Append(','); } Cell cell = this.GetCell(i, j); bool flag4 = cell == null || !cell.IsValidCell; if (flag4) { j++; } else { object data = cell.Data; bool flag5 = false; string text = data as string; bool flag6 = text != null; if (flag6) { bool flag7 = !string.IsNullOrEmpty(text) && (cell.DataFormat == CellDataFormatFlag.Text || text.IndexOf(',') >= 0 || text.IndexOf('"') >= 0 || text.StartsWith(" ") || text.EndsWith(" ")); if (flag7) { flag5 = true; } } else { text = Convert.ToString(data); } bool flag8 = flag5; if (flag8) { stringBuilder.Append('"'); stringBuilder.Append(text.Replace("\"", "\"\"")); stringBuilder.Append('"'); } else { stringBuilder.Append(text); } j += (int)cell.Colspan; } } } bool flag9 = stringBuilder.Length > 0; if (flag9) { streamWriter.WriteLine(stringBuilder.ToString()); stringBuilder.Length = 0; } } } public void AutoFillSerial(string fromAddressOrName, string toAddressOrName) { NamedRange namedRange; bool flag = this.TryGetNamedRange(fromAddressOrName, out namedRange); RangePosition position; if (flag) { position = namedRange.Position; } else { bool flag2 = RangePosition.IsValidAddress(fromAddressOrName); if (!flag2) { throw new InvalidAddressException(fromAddressOrName); } position = new RangePosition(fromAddressOrName); } NamedRange namedRange2; bool flag3 = this.TryGetNamedRange(toAddressOrName, out namedRange2); RangePosition position2; if (flag3) { position2 = namedRange2.Position; } else { bool flag4 = RangePosition.IsValidAddress(toAddressOrName); if (!flag4) { throw new InvalidAddressException(toAddressOrName); } position2 = new RangePosition(toAddressOrName); } this.AutoFillSerial(position, position2); } public void AutoFillSerial(RangePosition fromRange, RangePosition toRange) { fromRange = this.FixRange(fromRange); toRange = this.FixRange(toRange); bool flag = fromRange.IntersectWith(toRange); if (flag) { throw new ArgumentException("fromRange and toRange cannot being intersected."); } bool flag2 = toRange != this.CheckMergedRange(toRange); if (flag2) { throw new ArgumentException("cannot change a part of merged range."); } bool flag3 = this.CheckRangeReadonly(toRange); if (flag3) { throw new RangeContainsReadonlyCellsException(toRange); } bool flag4 = fromRange.Col == toRange.Col && fromRange.Cols == toRange.Cols; if (flag4) { for (int i = toRange.Col; i <= toRange.EndCol; i++) { List fromCells = this.GetColumnCellPositionsFromRange(fromRange, i); List toCells = this.GetColumnCellPositionsFromRange(toRange, i); this.AutoFillSerialCells(fromCells, toCells); } } else { bool flag5 = fromRange.Row == toRange.Row && fromRange.Rows == toRange.Rows; if (!flag5) { throw new InvalidOperationException("The fromRange and toRange must be having same number of rows or same number of columns."); } for (int j = toRange.Row; j <= toRange.EndRow; j++) { List fromCells = this.GetRowCellPositionsFromRange(fromRange, j); List toCells = this.GetRowCellPositionsFromRange(toRange, j); this.AutoFillSerialCells(fromCells, toCells); } } } private List GetColumnCellPositionsFromRange(RangePosition fromRange, int columnIndex) { List result = new List(); for (int i = fromRange.Row; i < fromRange.EndRow + 1; i++) { CellPosition cellPosition = new CellPosition(i, columnIndex); this.AddCellIfValid(cellPosition, result); } return result; } private List GetRowCellPositionsFromRange(RangePosition fromRange, int rowIndex) { List result = new List(); for (int i = fromRange.Col; i < fromRange.EndCol + 1; i++) { CellPosition cellPosition = new CellPosition(rowIndex, i); this.AddCellIfValid(cellPosition, result); } return result; } private void AddCellIfValid(CellPosition cellPosition, List result) { Cell cell = this.Cells[cellPosition]; bool flag = cell != null && !cell.IsValidCell; if (!flag) { result.Add(cellPosition); } } private void AutoFillSerialCells(List fromCells, List toCells) { bool flag = !fromCells.Any() || !toCells.Any(); if (!flag) { List values = (from cellPosition in fromCells select this[cellPosition]).ToList(); AutoFillSequence autoFillSequence = new AutoFillSequence(values); object[] array = autoFillSequence.Extrapolate(toCells.Count); for (int i = 0; i < toCells.Count; i++) { int index = i % fromCells.Count; CellPosition cellPosition3 = fromCells[index]; Cell cell = this.Cells[cellPosition3]; CellPosition cellPosition2 = toCells[i]; Cell cell2 = this.Cells[cellPosition2]; bool flag2 = !string.IsNullOrEmpty((cell != null) ? cell.InnerFormula : null); if (flag2) { FormulaRefactor.Reuse(this, cellPosition3, new RangePosition(cellPosition2)); } else { cell2.Data = array[i]; } } } } public void SetRangeDataFormat(string addressOrName, CellDataFormatFlag format, object dataFormatArgs = null) { bool flag = RangePosition.IsValidAddress(addressOrName); if (flag) { this.SetRangeDataFormat(new RangePosition(addressOrName), format, dataFormatArgs); } else { NamedRange refRange; bool flag2 = this.registeredNamedRanges.TryGetValue(addressOrName, out refRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } this.SetRangeDataFormat(refRange, format, dataFormatArgs); } } public void SetRangeDataFormat(int row, int col, int rows, int cols, CellDataFormatFlag format, object dataFormatArgs = null) { this.SetRangeDataFormat(new RangePosition(row, col, rows, cols), format, dataFormatArgs); } public void SetRangeDataFormat(RangePosition range, CellDataFormatFlag format, object dataFormatArgs = null) { RangePosition rangePosition = this.FixRange(range); int endRow = rangePosition.EndRow; int endCol = rangePosition.EndCol; List list = new List(10); for (int i = rangePosition.Row; i <= endRow; i++) { Cell cell; for (int j = rangePosition.Col; j <= endCol; j += (int)((cell.Colspan > 1) ? cell.Colspan : 1)) { cell = this.CreateAndGetCell(i, j); this.SetCellDataFormat(cell, format, ref dataFormatArgs, list); } } foreach (Cell cell2 in list) { this.RecalcCell(cell2, null); } this.RequestInvalidate(); } internal void SetCellDataFormat(CellPosition pos, CellDataFormatFlag format, ref object dataFormatArgs) { this.SetCellDataFormat(this.CreateAndGetCell(pos), format, ref dataFormatArgs, null); } internal void SetCellDataFormat(Cell cell, CellDataFormatFlag format, ref object dataFormatArgs, List formulaDirtyCells = null) { cell.DataFormat = format; cell.DataFormatArgs = dataFormatArgs; DataFormatterManager.Instance.FormatCell(cell); StyleUtility.UpdateCellRenderAlign(this, cell); this.UpdateCellTextBounds(cell); bool flag = formulaDirtyCells != null; if (flag) { Func callFunc = null; foreach (KeyValuePair> keyValuePair in this.formulaRanges) { IEnumerable value = keyValuePair.Value; Func predicate; if ((predicate = callFunc) == null) { predicate = (callFunc = ((ReferenceRange rr) => rr.Contains(cell.InternalPos))); } bool flag2 = value.Any(predicate); if (flag2) { bool flag3 = !formulaDirtyCells.Contains(keyValuePair.Key); if (flag3) { formulaDirtyCells.Add(keyValuePair.Key); } } } } } public CellDataFormatFlag GetCellDataFormat(string addressOrName, out object dataFormatArgs) { bool flag = CellPosition.IsValidAddress(addressOrName); CellDataFormatFlag cellDataFormat; if (flag) { cellDataFormat = this.GetCellDataFormat(new CellPosition(addressOrName), out dataFormatArgs); } else { RangePosition rangePosition; bool flag2 = this.TryGetNamedRangePosition(addressOrName, out rangePosition); if (!flag2) { throw new InvalidAddressException(addressOrName); } cellDataFormat = this.GetCellDataFormat(rangePosition.StartPos, out dataFormatArgs); } return cellDataFormat; } public CellDataFormatFlag GetCellDataFormat(CellPosition pos, out object dataFormatArgs) { pos = this.FixPos(pos); Cell cell = this.cells[pos.Row, pos.Col]; bool flag = cell == null; CellDataFormatFlag result; if (flag) { dataFormatArgs = null; result = CellDataFormatFlag.General; } else { result = this.GetCellDataFormat(cell, out dataFormatArgs); } return result; } internal CellDataFormatFlag GetCellDataFormat(Cell cell, out object dataFormatArgs) { dataFormatArgs = cell.DataFormatArgs; return cell.DataFormat; } public void DeleteRangeDataFormat(RangePosition range) { RangePosition rangePosition = this.FixRange(range); for (int i = rangePosition.Row; i <= rangePosition.EndRow; i++) { int j = rangePosition.Col; while (j <= rangePosition.EndCol) { Cell cell = this.cells[i, j]; bool flag = cell == null; if (flag) { j++; } else { cell.DataFormat = CellDataFormatFlag.General; cell.DataFormatArgs = null; bool isValidCell = cell.IsValidCell; if (isValidCell) { DataFormatterManager.Instance.FormatCell(cell); StyleUtility.UpdateCellRenderAlign(this, cell); this.UpdateCellTextBounds(cell); j += (int)((cell.Colspan > 1) ? cell.Colspan : 1); } else { j++; } } } } } public IFloatingObjectCollection FloatingObjects { get { return this.drawingCanvas.Children; } } public AutoColumnFilter CreateColumnFilter(string startColumn, string endColumn, int titleRows = 0, AutoColumnFilterUI columnFilterUI = AutoColumnFilterUI.DropdownButtonAndPanel) { int numberOfChar = RGUtility.GetNumberOfChar(startColumn); int numberOfChar2 = RGUtility.GetNumberOfChar(endColumn); return this.CreateColumnFilter(numberOfChar, numberOfChar2, titleRows, columnFilterUI); } public AutoColumnFilter CreateColumnFilter(int column, int titleRows, AutoColumnFilterUI columnFilterUI) { return this.CreateColumnFilter(column, column, titleRows, columnFilterUI); } public AutoColumnFilter CreateColumnFilter(int startColumn, int endColumn, int titleRows = 0, AutoColumnFilterUI columnFilterUI = AutoColumnFilterUI.DropdownButtonAndPanel) { bool flag = startColumn < 0 || startColumn >= this.ColumnCount; if (flag) { throw new ArgumentOutOfRangeException("startColumn", "number of column start to filter out of valid spreadsheet range"); } bool flag2 = endColumn < startColumn; if (flag2) { throw new ArgumentOutOfRangeException("endColumn", "end column must be greater than start column"); } bool flag3 = endColumn >= this.ColumnCount; if (flag3) { throw new ArgumentOutOfRangeException("endColumn", "end column out of valid spreadsheet range"); } return this.CreateColumnFilter(new RangePosition(titleRows, startColumn, this.MaxContentRow - titleRows + 1, endColumn - startColumn + 1), columnFilterUI); } public AutoColumnFilter CreateColumnFilter(RangePosition range, AutoColumnFilterUI columnFilterUI = AutoColumnFilterUI.DropdownButtonAndPanel) { AutoColumnFilter autoColumnFilter = new AutoColumnFilter(this, this.FixRange(range)); autoColumnFilter.Attach(this, columnFilterUI); return autoColumnFilter; } public void DoFilter(RangePosition range, Func filter) { try { this.controlAdapter.ChangeCursor(CursorStyle.Busy); this.SetRowsHeight(range.Row, range.Rows, delegate(int r) { bool flag2 = filter(r); bool flag3 = flag2; int result; if (flag3) { RowHeader rowHeader = this.RetrieveRowHeader(r); result = (int)((rowHeader.InnerHeight == 0) ? rowHeader.LastHeight : rowHeader.InnerHeight); } else { result = 0; } return result; }, true); } finally { bool flag = this.controlAdapter != null; if (flag) { this.ControlAdapter.ChangeCursor(CursorStyle.PlatformDefault); } } EventHandler rowsFiltered = this.RowsFiltered; if (rowsFiltered != null) { rowsFiltered(this, null); } } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler RowsFiltered; public RangePosition SortColumn(string columnAddress, SortOrder order = SortOrder.Ascending, CellElementFlag moveElementFlag = CellElementFlag.Data, Func cellDataComparer = null) { return this.SortColumn(RGUtility.GetNumberOfChar(columnAddress), order, moveElementFlag, cellDataComparer); } public RangePosition SortColumn(int columnIndex, SortOrder order = SortOrder.Ascending, CellElementFlag moveElementFlag = CellElementFlag.Data, Func cellDataComparer = null) { return this.SortColumn(columnIndex, 0, this.MaxContentRow, 0, this.MaxContentCol, order, moveElementFlag, cellDataComparer); } public RangePosition SortColumn(int columnIndex, int titleRows, SortOrder order = SortOrder.Ascending, CellElementFlag moveElementFlag = CellElementFlag.Data, Func cellDataComparer = null) { return this.SortColumn(columnIndex, titleRows, this.MaxContentRow, 0, this.MaxContentCol, order, moveElementFlag, cellDataComparer); } public RangePosition SortColumn(int columnIndex, int startRow, int endRow, int startColumn, int endColumn, SortOrder order = SortOrder.Ascending, CellElementFlag moveElementFlag = CellElementFlag.Data, Func cellDataComparer = null) { return this.SortColumn(columnIndex, new RangePosition(startRow, startColumn, this.MaxContentRow - startRow + 1, endColumn - startColumn + 1), order, cellDataComparer); } public RangePosition SortColumn(int columnIndex, string applyRange, SortOrder order = SortOrder.Ascending, CellElementFlag moveElementFlag = CellElementFlag.Data, Func cellDataComparer = null) { bool flag = RangePosition.IsValidAddress(applyRange); RangePosition result; if (flag) { result = this.SortColumn(columnIndex, new RangePosition(applyRange), order, cellDataComparer); } else { RangePosition applyRange2; bool flag2 = this.TryGetNamedRangePosition(applyRange, out applyRange2); if (!flag2) { throw new InvalidAddressException(applyRange); } result = this.SortColumn(columnIndex, applyRange2, order, cellDataComparer); } return result; } public RangePosition SortColumn(int columnIndex, RangePosition applyRange, SortOrder order = SortOrder.Ascending, Func cellDataComparer = null) { RangePosition range = this.FixRange(applyRange); RangePosition empty = RangePosition.Empty; bool flag = cellDataComparer != null; if (flag) { } Stopwatch stopwatch = Stopwatch.StartNew(); this.SuspendDataChangedEvents(); try { this.controlAdapter.ChangeCursor(CursorStyle.Busy); bool flag2 = !this.CheckQuickSortRange(range.Row, range.EndRow, range.Col, range.EndCol); if (flag2) { throw new InvalidOperationException("Cannot change a part of range, all cells should be having same colspan on column."); } IComparer comparer2; if (cellDataComparer != null) { IComparer comparer = new CellComparerAdapter(cellDataComparer, order); comparer2 = comparer; } else { IComparer comparer = new CellComparer(order); comparer2 = comparer; } IComparer cellComparer = comparer2; object[,] sortedData = this.GetSortedData(columnIndex, range.Row, range.EndRow, range.Col, range.EndCol, ref empty, cellComparer, order); this.DoAction(new SetSortedRangeDataAction(range, sortedData)); stopwatch.Stop(); bool flag3 = stopwatch.ElapsedMilliseconds > 10L; if (flag3) { Debug.WriteLine("sort column by {0} on [{1}-{2}]: {3} ms", new object[] { columnIndex, range.Col, range.EndCol, stopwatch.ElapsedMilliseconds }); } } finally { this.ResumeDataChangedEvents(); } this.RequestInvalidate(); this.controlAdapter.ChangeCursor(CursorStyle.PlatformDefault); bool flag4 = !empty.IsEmpty; if (flag4) { for (int i = empty.Col; i <= empty.EndCol; i++) { ColumnHeader columnHeader = this.cols[i]; bool flag5 = columnHeader.Body != null; if (flag5) { columnHeader.Body.OnDataChange(empty.Row, empty.EndRow); } } this.RaiseRangeDataChangedEvent(empty); EventHandler rowsSorted = this.RowsSorted; if (rowsSorted != null) { rowsSorted(this, new RangeEventArgs(empty)); } } return empty; } private bool CheckQuickSortRange(int row, int endRow, int col, int endCol) { for (int i = col; i <= endCol; i++) { Cell cell = this.cells[row, i]; for (int j = row + 1; j <= endRow; j++) { Cell cell2 = this.cells[j, i]; bool flag = cell != null && cell2 != null && ((cell.IsValidCell && !cell2.IsValidCell) || (!cell.IsValidCell && cell2.IsValidCell)); if (flag) { return false; } } } return true; } private object[,] GetSortedData(int columnIndex, int startRow, int endRow, int startColumn, int endColumn, ref RangePosition affectRange, IComparer cellComparer, SortOrder sortOrder) { bool isEmpty = affectRange.IsEmpty; if (isEmpty) { affectRange.Col = startColumn; affectRange.EndCol = endColumn; } int num = int.MaxValue; int num2 = int.MinValue; object[,] array = new object[endRow - startRow + 1, endColumn - startColumn + 1]; var source = from x in Enumerable.Range(startRow, endRow - startRow + 1) select new { Cells = (from y in Enumerable.Range(startColumn, endColumn - startColumn + 1) select this.cells[x, y]).ToArray() }; int columnRangeIndex = columnIndex - startColumn; source = ((sortOrder == SortOrder.Ascending) ? source.OrderBy(x=> { Cell cell3 = x.Cells[columnRangeIndex]; return (cell3 != null) ? cell3.InnerData : null; }, cellComparer) : source.OrderByDescending(x => { Cell cell3 = x.Cells[columnRangeIndex]; return (cell3 != null) ? cell3.InnerData : null; }, cellComparer)); var array2 = source.ToArray(); for (int i = 0; i < array2.Length; i++) { var fAnonymousType = array2[i]; for (int j = 0; j < endColumn - startColumn + 1; j++) { Cell cell = fAnonymousType.Cells[j]; object obj = (cell != null) ? cell.InnerData : null; bool flag; if (obj == null) { Cell cell2 = this.cells[i + startRow, j + startColumn]; flag = (((cell2 != null) ? cell2.InnerData : null) == null); } else { flag = false; } bool flag2 = flag; if (!flag2) { array[i, j] = obj; bool flag3 = num > i + startRow; if (flag3) { num = i + startRow; } bool flag4 = num2 < i + startRow; if (flag4) { num2 = i + startRow; } } } } affectRange.Row = ((num == int.MaxValue) ? 0 : num); affectRange.EndRow = ((num2 == int.MinValue) ? 0 : num2); return (!new RangePosition(startRow, startColumn, endRow - startRow + 1, endColumn - startColumn + 1).Equals(affectRange)) ? ((object[,])Worksheet.ResizeArray(array, new int[] { affectRange.Rows, affectRange.Cols })) : array; } private static Array ResizeArray(Array arr, int[] newSizes) { bool flag = newSizes.Length != arr.Rank; if (flag) { throw new ArgumentException("Array must have the same number of dimensions as there are elements in newSizes", "newSizes"); } Array array = Array.CreateInstance(arr.GetType().GetElementType(), newSizes); int length = (arr.Length <= array.Length) ? arr.Length : array.Length; Array.ConstrainedCopy(arr, 0, array, 0, length); return array; } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler RowsSorted; public void SetCellFormula(string addressOrName, string formula) { bool flag = CellPosition.IsValidAddress(addressOrName); if (flag) { this.SetCellFormula(new CellPosition(addressOrName), formula); } else { NamedRange namedRange; bool flag2 = this.registeredNamedRanges.TryGetValue(addressOrName, out namedRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } this.SetCellFormula(namedRange.StartPos, formula); } } public void SetCellFormula(int row, int col, string formula) { this.SetCellFormula(this.CreateAndGetCell(row, col), formula); } public void SetCellFormula(CellPosition pos, string formula) { this.SetCellFormula(pos.Row, pos.Col, formula); } internal void SetCellFormula(Cell cell, string formula) { cell.InnerFormula = formula; this.ClearCellReferenceList(cell); cell.formulaStatus = FormulaStatus.Normal; STNode stnode = null; try { stnode = Parser.Parse(this.workbook, cell, formula); } catch (Exception ex) { cell.formulaStatus = FormulaStatus.SyntaxError; this.NotifyExceptionHappen(ex); } bool flag = stnode != null; if (flag) { this.SetCellFormula(cell, stnode); } } internal void SetCellFormula(Cell cell, STNode node) { cell.formulaStatus = FormulaStatus.Normal; List list; bool flag = this.formulaRanges.TryGetValue(cell, out list); if (flag) { list.Clear(); } else { list = (this.formulaRanges[cell] = new List()); } bool flag2 = node != null; if (flag2) { this.RemoveCellTraceDependents(cell); this.RemoveCellTracePrecedents(cell); try { Worksheet.IterateToAddReference(cell, node, list, true); cell.FormulaTree = node; } catch (CircularReferenceException ex) { cell.FormulaTree = null; cell.InnerFormula = null; cell.formulaStatus = FormulaStatus.CircularReference; this.NotifyExceptionHappen(ex); } } } private static void AddCellReferenceIntoList(List referencedRanges, ReferenceRange range) { bool flag = referencedRanges.All((ReferenceRange rr) => rr.Worksheet == range.Worksheet && !rr.Contains(range)); if (flag) { referencedRanges.Add(range); } } internal static void IterateToAddReference(Cell cell, STNode node, List referencedRanges, bool checkSelfRefer) { bool flag = node == null; if (!flag) { switch (node.Type) { case STNodeType.IDENTIFIER: { STIdentifierNode stidentifierNode = (STIdentifierNode)node; Worksheet worksheet = stidentifierNode.Worksheet; bool flag2 = worksheet == null; if (flag2) { worksheet = cell.Worksheet; } NamedRange namedRange; bool flag3 = worksheet.TryGetNamedRange(stidentifierNode.Identifier, out namedRange); if (flag3) { bool flag4 = checkSelfRefer && namedRange.Contains(cell.Position) && worksheet == cell.Worksheet; if (flag4) { throw new CircularReferenceException(); } Worksheet.AddCellReferenceIntoList(referencedRanges, namedRange); } return; } case STNodeType.RANGE: { STRangeNode strangeNode = (STRangeNode)node; Worksheet worksheet = strangeNode.Worksheet; bool flag5 = worksheet == null; if (flag5) { worksheet = cell.Worksheet; } RangePosition range = worksheet.FixRange(strangeNode.Range); bool flag6 = checkSelfRefer && range.Contains(cell.Position) && worksheet == cell.Worksheet; if (flag6) { throw new CircularReferenceException(); } Worksheet.AddCellReferenceIntoList(referencedRanges, new ReferenceRange(worksheet, range)); return; } case STNodeType.CELL: { STCellNode stcellNode = (STCellNode)node; CellPosition position = stcellNode.Position; Worksheet worksheet = stcellNode.Worksheet; bool flag7 = worksheet == null; if (flag7) { worksheet = cell.Worksheet; } bool flag8 = checkSelfRefer && position.Equals(cell.Position) && worksheet == cell.Worksheet; if (flag8) { throw new CircularReferenceException(); } bool flag9 = position.Row >= worksheet.RowCount || position.Col >= worksheet.ColumnCount; if (flag9) { throw new ArgumentOutOfRangeException(); } Cell cell2 = worksheet.CreateAndGetCell(position); Worksheet.AddCellReferenceIntoList(referencedRanges, new ReferenceRange(worksheet, cell2, cell2)); return; } case STNodeType.FUNCTION_CALL: { STFunctionNode stfunctionNode = (STFunctionNode)node; string text = stfunctionNode.Name; string a = text; if (!(a == "ROW") && !(a == "COLUMN") && !(a == "ADDRESS") && !(a == "INDIRECT")) { bool flag10 = stfunctionNode.Children != null; if (flag10) { foreach (STNode node2 in stfunctionNode.Children) { Worksheet.IterateToAddReference(cell, node2, referencedRanges, checkSelfRefer); } } } else { bool flag11 = stfunctionNode.Children != null; if (flag11) { foreach (STNode node3 in stfunctionNode.Children) { Worksheet.IterateToAddReference(cell, node3, referencedRanges, false); } } } return; } } bool flag12 = node.Children != null; if (flag12) { foreach (STNode node4 in node.Children) { Worksheet.IterateToAddReference(cell, node4, referencedRanges, checkSelfRefer); } } } } public void DeleteCellFormula(string addressOrName) { bool flag = CellPosition.IsValidAddress(addressOrName); if (flag) { CellPosition cellPosition = new CellPosition(addressOrName); this.DeleteCellFormula(cellPosition.Row, cellPosition.Col); } else { bool flag2 = RangePosition.IsValidAddress(addressOrName); if (flag2) { this.ClearRangeContent(new RangePosition(addressOrName), CellElementFlag.Formula, true); } else { NamedRange namedRange; bool flag3 = this.TryGetNamedRange(addressOrName, out namedRange); if (flag3) { bool isMergedCell = namedRange.IsMergedCell; if (isMergedCell) { this.DeleteCellFormula(namedRange.StartPos); } else { this.ClearRangeContent(namedRange, CellElementFlag.Formula, true); } } } } } public void DeleteCellFormula(CellPosition pos) { this.DeleteCellFormula(pos.Row, pos.Col); } public void DeleteCellFormula(int row, int col) { Cell cell = this.cells[row, col]; bool flag = cell != null; if (flag) { this.DeleteCellFormula(cell); } } public void DeleteCellFormula(Cell cell) { cell.InnerFormula = null; cell.InnerData = null; cell.InnerDisplay = null; cell.FontDirty = false; this.RequestInvalidate(); } public void RecalcCell(string address) { bool flag = CellPosition.IsValidAddress(address); if (flag) { this.RecalcCell(new CellPosition(address)); } else { RangePosition rangePosition; bool flag2 = this.TryGetNamedRangePosition(address, out rangePosition); if (!flag2) { throw new InvalidAddressException(address); } this.RecalcCell(rangePosition.StartPos); } } public void RecalcCell(CellPosition pos) { this.RecalcCell(pos.Row, pos.Col); } public void RecalcCell(int row, int col) { Cell cell = this.GetCell(row, col); bool flag = cell == null; if (!flag) { this.RecalcCell(cell, null); } } internal void RecalcCell(Cell cell, Stack> dirtyCellStack = null) { bool flag = !cell.HasFormula; if (!flag) { object data = null; bool flag2 = cell.formulaStatus != FormulaStatus.CircularReference && cell.formulaStatus != FormulaStatus.SyntaxError; if (flag2) { try { data = Evaluator.CheckAndGetDefaultValue(cell, Evaluator.Evaluate(cell, cell.FormulaTree)).value; cell.formulaStatus = FormulaStatus.Normal; } catch (FormulaTypeMismatchException) { cell.formulaStatus = FormulaStatus.InvalidValue; } catch (FormulaNoNameException) { cell.formulaStatus = FormulaStatus.NameNotFound; } catch (FormulaParameterMismatchException) { cell.formulaStatus = FormulaStatus.MismatchedParameter; } catch (Exception ex) { cell.formulaStatus = FormulaStatus.UnspecifiedError; this.NotifyExceptionHappen(ex); } } this.UpdateCellData(cell, data, dirtyCellStack); } } public void SuspendFormulaReferenceUpdates() { this.settings &= ~WorksheetSettings.Formula_AutoUpdateReferenceCell; } public void ResumeFormulaReferenceUpdates() { this.settings |= WorksheetSettings.Formula_AutoUpdateReferenceCell; } private static void UpdateWorksheetReferencedFormulaCells(Worksheet worksheet, Cell fromCell, Stack> dirtyCellStack = null) { List list = null; using (Dictionary>.Enumerator enumerator = worksheet.formulaRanges.GetEnumerator()) { Func callFunc = null; while (enumerator.MoveNext()) { KeyValuePair> range = enumerator.Current; IEnumerable value = range.Value; Func predicate; if ((predicate = callFunc) == null) { predicate = (callFunc = ((ReferenceRange r) => r.Contains(fromCell.InternalPos))); } bool flag = value.Any(predicate); if (flag) { bool flag2 = (list == null || !list.Contains(range.Key)) && (dirtyCellStack == null || dirtyCellStack.All((List s) => !s.Contains(range.Key))); if (flag2) { bool flag3 = list == null; if (flag3) { list = new List(); } list.Add(range.Key); } } } } bool flag4 = list != null && list.Count > 0; if (flag4) { try { bool flag5 = dirtyCellStack == null; if (flag5) { dirtyCellStack = new Stack>(); } dirtyCellStack.Push(list); foreach (Cell cell in list) { try { worksheet.RecalcCell(cell, dirtyCellStack); } catch (Exception ex) { worksheet.NotifyExceptionHappen(ex); } } } finally { dirtyCellStack.Pop(); } } } internal void UpdateReferencedFormulaCells(Cell cell, Stack> dirtyCellStack = null) { bool flag = this.workbook == null; if (flag) { Worksheet.UpdateWorksheetReferencedFormulaCells(this, cell, dirtyCellStack); } else { foreach (Worksheet worksheet in this.workbook.worksheets) { Worksheet.UpdateWorksheetReferencedFormulaCells(worksheet, cell, dirtyCellStack); } } } internal void ClearCellReferenceList(Cell cell) { List list; bool flag = this.formulaRanges.TryGetValue(cell, out list); if (flag) { list.Clear(); } } public List GetCellFormulaReferenceRanges(string address) { bool flag = CellPosition.IsValidAddress(address); List result; if (flag) { result = this.GetCellFormulaReferenceRanges(new CellPosition(address)); } else { result = null; } return result; } public List GetCellFormulaReferenceRanges(CellPosition pos) { Cell cell = this.cells[pos.Row, pos.Col]; return (cell == null) ? null : this.GetCellFormulaReferenceRanges(cell); } public List GetCellFormulaReferenceRanges(Cell cell) { List list; bool flag = this.formulaRanges.TryGetValue(cell, out list); List result; if (flag) { result = list; } else { result = null; } return result; } public string GetCellFormula(string addressOrName) { bool flag = CellPosition.IsValidAddress(addressOrName); string cellFormula; if (flag) { cellFormula = this.GetCellFormula(new CellPosition(addressOrName)); } else { NamedRange namedRange; bool flag2 = this.registeredNamedRanges.TryGetValue(addressOrName, out namedRange); if (!flag2) { throw new InvalidReferenceException("Specified reference neither is an valid address nor name registered in spreadsheet."); } cellFormula = this.GetCellFormula(namedRange.StartPos); } return cellFormula; } public string GetCellFormula(CellPosition pos) { Cell cell = this.GetCell(pos); return (cell == null) ? string.Empty : cell.InnerFormula; } public bool TraceCellPrecedents(string address) { return CellPosition.IsValidAddress(address) && this.TraceCellPrecedents(new CellPosition(address)); } public bool TraceCellPrecedents(CellPosition pos) { Cell cell = this.GetCell(pos); return cell != null && this.TraceCellPrecedents(cell); } internal bool TraceCellPrecedents(Cell cell) { bool flag = !cell.HasFormula; bool result; if (flag) { result = false; } else { List cellFormulaReferenceRanges = this.GetCellFormulaReferenceRanges(cell); bool flag2 = cellFormulaReferenceRanges == null; if (flag2) { result = false; } else { foreach (ReferenceRange referenceRange in cellFormulaReferenceRanges) { this.AddTraceLine(this.GetCell(referenceRange.StartPos), cell); } this.RequestInvalidate(); result = true; } } return result; } public bool RemoveCellTracePrecedents(string address) { return CellPosition.IsValidAddress(address) && this.RemoveCellTracePrecedents(new CellPosition(address)); } public bool RemoveCellTracePrecedents(CellPosition pos) { Cell cell = this.GetCell(pos); return cell != null && this.RemoveCellTracePrecedents(cell); } public bool RemoveCellTracePrecedents(Cell cell) { bool flag = false; List list = null; bool flag2 = this.traceDependentArrows != null; if (flag2) { Func callFunc = null; foreach (Cell cell2 in this.traceDependentArrows.Keys) { List list2 = this.traceDependentArrows[cell2]; IEnumerable source = list2; Func predicate; if ((predicate = callFunc) == null) { predicate = (callFunc = ((Cell l) => l == cell)); } Cell cell3 = source.FirstOrDefault(predicate); bool flag3 = cell3 != null; if (flag3) { list2.Remove(cell3); flag = true; bool flag4 = list2.Count == 0; if (flag4) { bool flag5 = list == null; if (flag5) { list = new List(); } list.Add(cell2); } } } bool flag6 = list != null; if (flag6) { foreach (Cell key in list) { this.traceDependentArrows.Remove(key); } } } bool flag7 = flag; if (flag7) { this.RequestInvalidate(); } return flag; } public bool TraceCellDependents(string address) { return CellPosition.IsValidAddress(address) && this.TraceCellDependents(new CellPosition(address)); } public bool TraceCellDependents(CellPosition pos) { Cell cell = this.GetCell(pos); return cell != null && this.TraceCellPrecedents(cell); } public bool TraceCellDependents(Cell cell) { bool flag = !cell.HasFormula; bool result; if (flag) { result = false; } else { bool flag2 = this.traceDependentArrows.Keys.Contains(cell); if (flag2) { result = false; } else { bool flag3 = false; Func callFunc = null; foreach (Cell cell2 in this.formulaRanges.Keys) { List list = this.formulaRanges[cell2]; IEnumerable source = list; Func predicate; if ((predicate = callFunc) == null) { predicate = (callFunc = ((ReferenceRange rr) => rr.Contains(cell.InternalPos))); } bool flag4 = source.Any(predicate); if (flag4) { this.AddTraceLine(cell, cell2); flag3 = true; } } bool flag5 = flag3; if (flag5) { this.RequestInvalidate(); } result = true; } } return result; } public bool RemoveCellTraceDependents(string address) { return CellPosition.IsValidAddress(address) && this.RemoveCellTraceDependents(new CellPosition(address)); } public bool RemoveCellTraceDependents(CellPosition pos) { Cell cell = this.GetCell(pos); return cell != null && this.RemoveCellTraceDependents(cell); } public bool RemoveCellTraceDependents(Cell cell) { bool flag = this.traceDependentArrows != null && this.traceDependentArrows.Keys.Contains(cell); bool result; if (flag) { this.traceDependentArrows.Remove(cell); this.RequestInvalidate(); result = true; } else { result = false; } return result; } internal bool AddTraceLine(Cell fromCell, Cell toCell) { bool flag = this.traceDependentArrows == null; if (flag) { this.traceDependentArrows = new Dictionary>(); } bool flag2 = this.traceDependentArrows.Keys.Contains(fromCell); bool result; if (flag2) { result = false; } else { List list; bool flag3 = this.traceDependentArrows.TryGetValue(fromCell, out list); if (flag3) { bool flag4 = list.Any((Cell l) => l.InternalPos == toCell.InternalPos); if (flag4) { return false; } } else { list = (this.traceDependentArrows[fromCell] = new List()); } list.Add(toCell); this.RequestInvalidate(); result = true; } return result; } internal bool RemoveTraceLine(Cell fromCell, Cell toCell) { bool flag = !this.traceDependentArrows.Keys.Contains(fromCell); bool result; if (flag) { result = false; } else { List list; bool flag2 = this.traceDependentArrows.TryGetValue(fromCell, out list); if (flag2) { Cell cell = list.FirstOrDefault((Cell l) => l.InternalPos == toCell.InternalPos); bool flag3 = cell != null; if (flag3) { list.Remove(cell); } bool flag4 = list.Count == 0; if (flag4) { this.traceDependentArrows.Remove(fromCell); } this.RequestInvalidate(); result = true; } else { result = false; } } return result; } public void RemoveCellAllTraceArrows(string address) { bool flag = CellPosition.IsValidAddress(address); if (flag) { this.RemoveCellAllTraceArrows(new CellPosition(address)); } } public void RemoveCellAllTraceArrows(CellPosition pos) { this.RemoveCellTraceDependents(pos); this.RemoveCellTracePrecedents(pos); } internal bool RemoveCellAllTraceArrows(Cell cell) { this.RemoveCellTraceDependents(cell); this.RemoveCellTracePrecedents(cell); return true; } public bool RemoveRangeAllTraceArrows(string address) { bool flag = RangePosition.IsValidAddress(address); bool result; if (flag) { this.RemoveRangeAllTraceArrows(new RangePosition(address)); result = true; } else { result = false; } return result; } public void RemoveRangeAllTraceArrows(RangePosition range) { this.IterateCells(range, (int r, int c, Cell cell) => this.RemoveCellAllTraceArrows(cell)); } public bool IsCellInTracePrecedents(CellPosition pos) { bool flag = this.traceDependentArrows == null; Func callFunc = null; return !flag && this.traceDependentArrows.Values.Any(delegate(List ls) { Func predicate; if ((predicate = callFunc) == null) { predicate = (callFunc = ((Cell l) => l.InternalPos == pos)); } return ls.Any(predicate); }); } public bool IsCellInTraceDependents(CellPosition pos) { bool flag = this.traceDependentArrows == null; return !flag && this.traceDependentArrows.Keys.Any((Cell c) => c.InternalPos == pos); } public IEnumerable GetAllTraceDependentCells() { return this.traceDependentArrows.Keys; } public void Recalculate() { Stack> dirtyCells = new Stack>(); RangePosition range = new RangePosition(0, 0, this.MaxContentRow + 1, this.MaxContentCol + 1); this.IterateCells(range, delegate(int row, int col, Cell cell) { bool hasFormula = cell.HasFormula; if (hasFormula) { this.RecalcCell(cell, dirtyCells); } return true; }); } public int RowHeaderWidth { get { return (int)this.rowHeaderWidth; } set { bool flag = value == -1; if (flag) { this.userRowHeaderWidth = false; this.AutoAdjustRowHeaderPanelWidth(); } else { bool flag2 = value == 0; if (flag2) { this.SetSettings(WorksheetSettings.View_ShowRowHeader, false); } else { this.userRowHeaderWidth = true; this.rowHeaderWidth = (ushort)value; bool flag3 = this.viewportController != null; if (flag3) { this.viewportController.UpdateController(); } } } } } private void AutoAdjustRowHeaderPanelWidth() { bool flag = !this.userRowHeaderWidth; if (flag) { this.rowHeaderWidth = (ushort)((this.rows.Count >= 100000) ? 50 : 40); } } public void SetColumnsWidth(int col, int count, ushort width) { this.SetColumnsWidth(col, count, (int c) => (int)width, true, true); } internal void SetColumnsWidth(int col, int count, Func widthGetter, bool processOutlines = true, bool updateMaxColumnHeader = true) { Stopwatch stopwatch = Stopwatch.StartNew(); int num = col + count; int num2 = 0; float num3 = 0f; OutlineCollection outlineCollection = this.GetOutlines(RowOrColumn.Column); bool flag = updateMaxColumnHeader && this.maxColumnHeader < num - 1; if (flag) { this.maxColumnHeader = num - 1; } int num4 = Math.Min(this.rows.Count, this.cells.MaxRow + 1); int count2 = this.cols.Count; int c; int c2; for (c = col; c < count2; c = c2 + 1) { ColumnHeader columnHeader = this.cols[c]; columnHeader.Left += num2; int innerWidth = (int)columnHeader.InnerWidth; int num5 = 0; bool flag2 = false; bool flag3 = c < num; if (flag3) { num5 = widthGetter(c); bool flag4 = num5 >= 0; if (flag4) { bool flag5 = num5 == 0 && columnHeader.InnerWidth <= 0; if (flag5) { flag2 = true; } else { columnHeader.LastWidth = columnHeader.InnerWidth; columnHeader.InnerWidth = (ushort)num5; bool flag6 = num5 > 0; if (flag6) { bool flag7 = processOutlines && outlineCollection != null; if (flag7) { outlineCollection.IterateOutlines(delegate(ReoGridOutline o) { bool flag17 = o.End == c + 1 && o.InternalCollapsed; bool result; if (flag17) { o.InternalCollapsed = false; o.RaiseAfterExpandingEvent(); result = false; } else { result = true; } return result; }); } } else { bool flag8 = processOutlines && outlineCollection != null; if (flag8) { outlineCollection.IterateOutlines(delegate(ReoGridOutline o) { bool flag17 = o.End == c + 1 && !o.InternalCollapsed; if (flag17) { bool flag18 = true; for (int k = o.Start; k < o.End; k++) { bool flag19 = this.cols[k].InnerWidth > 0; if (flag19) { flag18 = false; break; } } bool flag20 = flag18; if (flag20) { o.InternalCollapsed = true; o.RaiseAfterCollapseEvent(); return false; } } return true; }); } } } } else { num5 = 0; } } for (int i = 0; i < num4; i++) { Cell cell = this.cells[i, c]; bool flag9 = cell != null; if (flag9) { bool isEndMergedCell = cell.IsEndMergedCell; if (isEndMergedCell) { Cell cell2 = this.GetCell(cell.MergeStartPos); this.UpdateCellBounds(cell2); cell2.UpdateContentBounds(); } else { cell.Left += (float)num2; cell.TextBoundsLeft += num3; bool flag10 = cell.InternalCol < num && cell.Colspan == 1 && cell.Rowspan == 1; if (flag10) { cell.Width = (float)(num5 + 1); this.UpdateCellTextBounds(cell); } cell.UpdateContentBounds(); } } } bool flag11 = c < num && !flag2; if (flag11) { num2 += num5 - innerWidth; num3 = (float)num2 * this.renderScaleFactor; } c2 = c; } bool flag12 = this.drawingCanvas.drawingObjects != null && this.drawingCanvas.drawingObjects.Count > 0; if (flag12) { int left = this.cols[col].Left; int right = this.cols[col + count - 1].Right; foreach (IDrawingObject drawingObject in this.drawingCanvas.drawingObjects) { bool flag13 = drawingObject.Left > (float)left; if (flag13) { drawingObject.X += (float)num2; } else { bool flag14 = drawingObject.Right > (float)left; if (flag14) { drawingObject.Width += (float)num2; } } } } this.UpdateViewportController(); bool flag15 = !this.suspendingUIUpdates; if (flag15) { int num6 = Math.Min(num, count2); for (int j = col; j < num6; j++) { this.cols[j].RaiseWidthChangedEvent(); } } EventHandler columnsWidthChanged = this.ColumnsWidthChanged; if (columnsWidthChanged != null) { columnsWidthChanged(this, new ColumnsWidthChangedEventArgs(col, count, widthGetter(col))); } stopwatch.Stop(); bool flag16 = stopwatch.ElapsedMilliseconds > 5L; if (flag16) { Debug.WriteLine(string.Format("columns width change takes {0} ms.", stopwatch.ElapsedMilliseconds)); } } public void SetRowsHeight(int row, int count, ushort height) { this.SetRowsHeight(row, count, (int r) => (int)height, true); } internal void SetRowsHeight(int row, int count, Func heightGetter, bool processOutlines) { Stopwatch stopwatch = Stopwatch.StartNew(); int num = row + count; int num2 = 0; float num3 = 0f; OutlineCollection outlineCollection = this.GetOutlines(RowOrColumn.Row); bool flag = this.maxRowHeader < num - 1; if (flag) { this.maxRowHeader = num - 1; } int count2 = this.rows.Count; int num4 = Math.Min(this.cols.Count, this.cells.MaxCol + 1); int r; int r2; for (r = row; r < count2; r = r2 + 1) { RowHeader rowHeader = this.rows[r]; rowHeader.Top += num2; int innerHeight = (int)rowHeader.InnerHeight; int num5 = 0; bool flag2 = false; bool flag3 = r < num; if (flag3) { num5 = heightGetter(r); bool flag4 = num5 >= 0; if (flag4) { bool flag5 = num5 == 0 && rowHeader.InnerHeight <= 0; if (flag5) { flag2 = true; } else { rowHeader.LastHeight = rowHeader.InnerHeight; rowHeader.InnerHeight = (ushort)num5; bool flag6 = num5 > 0; if (flag6) { bool flag7 = processOutlines && outlineCollection != null; if (flag7) { outlineCollection.IterateOutlines(delegate(ReoGridOutline o) { bool flag17 = o.End == r + 1 && o.InternalCollapsed; if (flag17) { o.InternalCollapsed = false; o.RaiseAfterExpandingEvent(); } return true; }); } } else { bool flag8 = processOutlines && outlineCollection != null; if (flag8) { outlineCollection.IterateOutlines(delegate(ReoGridOutline o) { bool flag17 = o.End == r + 1 && !o.InternalCollapsed; if (flag17) { bool flag18 = true; for (int k = o.Start; k < o.End; k++) { bool flag19 = this.rows[k].InnerHeight > 0; if (flag19) { flag18 = false; break; } } bool flag20 = flag18; if (flag20) { o.InternalCollapsed = true; o.RaiseAfterCollapseEvent(); return true; } } return true; }); } } } } else { num5 = 0; } } for (int i = 0; i < num4; i++) { Cell cell = this.cells[r, i]; bool flag9 = cell != null; if (flag9) { bool isEndMergedCell = cell.IsEndMergedCell; if (isEndMergedCell) { Cell cell2 = this.GetCell(cell.MergeStartPos); this.UpdateCellBounds(cell2); } else { cell.Top += (float)num2; cell.TextBoundsTop += num3; bool flag10 = cell.InternalRow < num && cell.Colspan == 1 && cell.Rowspan == 1; if (flag10) { cell.Height = (float)(num5 + 1); this.UpdateCellTextBounds(cell); } cell.UpdateContentBounds(); } } } bool flag11 = r < num && !flag2; if (flag11) { num2 += num5 - innerHeight; num3 = (float)num2 * this.renderScaleFactor; } r2 = r; } bool flag12 = this.drawingCanvas.drawingObjects != null && this.drawingCanvas.drawingObjects.Count > 0; if (flag12) { int top = this.rows[row].Top; int bottom = this.rows[row + count - 1].Bottom; foreach (IDrawingObject drawingObject in this.drawingCanvas.drawingObjects) { bool flag13 = drawingObject.Top > (float)top; if (flag13) { drawingObject.Y += (float)num2; } else { bool flag14 = drawingObject.Bottom > (float)top; if (flag14) { drawingObject.Height += (float)num2; } } } } this.UpdateViewportController(); bool flag15 = !this.suspendingUIUpdates; if (flag15) { int num6 = Math.Min(num, count2); for (int j = row; j < num6; j++) { this.rows[j].RaiseHeightChangedEvent(); } } EventHandler rowsHeightChanged = this.RowsHeightChanged; if (rowsHeightChanged != null) { rowsHeightChanged(this, new RowsHeightChangedEventArgs(row, count, heightGetter(row))); } stopwatch.Stop(); long elapsedMilliseconds = stopwatch.ElapsedMilliseconds; bool flag16 = elapsedMilliseconds > 10L; if (flag16) { Debug.WriteLine(string.Format("row height changed: {0} ms.", elapsedMilliseconds)); } } public ushort GetColumnWidth(int col) { bool flag = col < 0 || col >= this.ColumnCount; if (flag) { throw new ArgumentOutOfRangeException("col", "invalid column index"); } return this.cols[col].InnerWidth; } public ushort GetRowHeight(int row) { bool flag = row < 0 || row >= this.RowCount; if (flag) { throw new ArgumentOutOfRangeException("row", "invalid row index"); } return this.rows[row].InnerHeight; } internal bool ExpandRowHeightToFitCell(Cell cell) { bool flag = !cell.IsValidCell; bool result; if (flag) { result = false; } else { bool fontDirty = cell.FontDirty; if (fontDirty) { this.UpdateCellFont(cell, UpdateFontReason.FontChanged); } bool flag2 = !string.IsNullOrEmpty(cell.DisplayText); if (flag2) { int num = (int)Math.Ceiling((double)(cell.TextBounds.Height / this.renderScaleFactor)); bool flag3 = num > 65535; if (flag3) { num = 65535; } bool flag4 = cell.Height < (float)num; if (flag4) { this.SetRowsHeight(cell.InternalRow, 1, (ushort)num); return true; } } result = false; } return result; } internal bool ExpandColumnWidthFitToCell(Cell cell) { bool flag = !cell.IsValidCell; bool result; if (flag) { result = false; } else { bool fontDirty = cell.FontDirty; if (fontDirty) { this.UpdateCellFont(cell, UpdateFontReason.FontChanged); } bool flag2 = !string.IsNullOrEmpty(cell.DisplayText); if (flag2) { int num = (int)Math.Ceiling((double)(cell.TextBounds.Width / this.renderScaleFactor)); bool flag3 = num > 65535; if (flag3) { num = 65535; } bool flag4 = cell.Width < (float)num; if (flag4) { this.SetColumnsWidth(cell.InternalCol, 1, (ushort)num); return true; } } result = false; } return result; } public bool AutoFitRowHeight(int row, bool byAction = false) { bool flag = row < 0 || row > this.rows.Count - 1; if (flag) { throw new ArgumentOutOfRangeException("row"); } float num = 0f; for (int i = 0; i <= this.MaxContentCol; i++) { Cell cell = this.cells[row, i]; bool flag2 = cell != null && cell.Rowspan == 1; if (flag2) { bool fontDirty = cell.FontDirty; if (fontDirty) { this.UpdateCellFont(cell, UpdateFontReason.FontChanged); } RichText richText = cell.Data as RichText; bool flag3 = richText != null; if (flag3) { float height = richText.TextSize.Height; bool flag4 = num < height; if (flag4) { num = height; } } else { float num2 = cell.TextBounds.Height / this.renderScaleFactor; bool flag5 = num < num2; if (flag5) { num = num2; } } } } bool flag6 = num > 0f; bool result; if (flag6) { bool flag7 = num < 0f; if (flag7) { num = 0f; } bool flag8 = num > 65533f; if (flag8) { num = 65533f; } ushort height2 = (ushort)(num + 2f); if (byAction) { this.DoAction(new SetRowsHeightAction(row, 1, height2)); } else { this.SetRowsHeight(row, 1, height2); } result = true; } else { result = false; } return result; } public bool AutoFitColumnWidth(int col, bool byAction = false) { bool flag = col < 0 || col > this.cols.Count - 1; if (flag) { throw new ArgumentOutOfRangeException("col"); } float num = 0f; for (int i = 0; i <= this.MaxContentRow; i++) { Cell cell = this.cells[i, col]; bool flag2 = cell != null && cell.Colspan == 1; if (flag2) { bool fontDirty = cell.FontDirty; if (fontDirty) { this.UpdateCellFont(cell, UpdateFontReason.FontChanged); } RichText richText = cell.Data as RichText; bool flag3 = richText != null; if (flag3) { float width = richText.TextSize.Width; bool flag4 = num < width; if (flag4) { num = width; } } else { float num2 = cell.TextBounds.Width / this.renderScaleFactor; bool flag5 = num < num2; if (flag5) { num = num2; } } } } bool flag6 = num > 0f; bool result; if (flag6) { bool flag7 = num < 0f; if (flag7) { num = 0f; } bool flag8 = num > 65533f; if (flag8) { num = 65533f; } ushort width2 = (ushort)(num + 2f); if (byAction) { this.DoAction(new SetColumnsWidthAction(col, 1, width2)); } else { this.SetColumnsWidth(col, 1, width2); } result = true; } else { result = false; } return result; } public void AppendColumns(int count) { bool flag = count < 0; if (flag) { throw new ArgumentException("count must be greater than zero"); } bool flag2 = this.cols.Count + count > this.cells.RowCapacity; if (flag2) { throw new ArgumentOutOfRangeException("count", "number of columns exceeds the maximum columns: " + this.cells.ColCapacity.ToString()); } int num = (this.cols.Count == 0) ? 0 : this.cols[this.cols.Count - 1].Right; int num2 = this.cols.Count + count; for (int i = this.cols.Count; i < num2; i++) { this.cols.Add(new ColumnHeader(this) { InnerWidth = this.defaultColumnWidth, Col = i, RenderText = RGUtility.GetAlphaChar((long)i), Left = num, IsAutoWidth = true }); num += (int)this.defaultColumnWidth; } this.UpdateViewportController(); EventHandler columnsInserted = this.ColumnsInserted; if (columnsInserted != null) { columnsInserted(this, new ColumnsInsertedEventArgs(this.cols.Count - count, count)); } } public void AppendRows(int count) { bool flag = count < 0; if (flag) { throw new ArgumentException("count must be greater than zero"); } bool flag2 = this.rows.Count + count > this.cells.RowCapacity; if (flag2) { throw new ArgumentOutOfRangeException("count", "number of rows exceeds the maximum rows: " + this.cells.RowCapacity.ToString()); } int num = (this.rows.Count == 0) ? 0 : this.rows[this.rows.Count - 1].Bottom; int num2 = this.rows.Count + count; for (int i = this.rows.Count; i < num2; i++) { this.rows.Add(new RowHeader(this) { InnerHeight = this.defaultRowHeight, Row = i, Top = num, IsAutoHeight = true }); num += (int)this.defaultRowHeight; } this.UpdateViewportController(); EventHandler rowsInserted = this.RowsInserted; if (rowsInserted != null) { rowsInserted(this, new RowsInsertedEventArgs(this.rows.Count - count, count)); } } public void Resize(int rows, int cols) { bool flag = cols > 0; if (flag) { bool flag2 = cols > this.cols.Count; if (flag2) { this.AppendColumns(cols - this.cols.Count); } else { bool flag3 = cols < this.cols.Count; if (flag3) { this.DeleteColumns(cols, this.cols.Count - cols); } } } bool flag4 = rows > 0; if (flag4) { bool flag5 = rows > this.rows.Count; if (flag5) { this.AppendRows(rows - this.rows.Count); } else { bool flag6 = rows < this.rows.Count; if (flag6) { this.DeleteRows(rows, this.rows.Count - rows); } } } } public void SetCols(int colCount) { this.Resize(-1, colCount); } public void SetRows(int rowCount) { this.Resize(rowCount, -1); } public int Rows { get { return this.rows.Count; } set { this.SetRows(value); } } public int Columns { get { return this.cols.Count; } set { this.SetCols(value); } } public void InsertRows(int row, int count) { bool flag = row > this.rows.Count; if (flag) { throw new ArgumentOutOfRangeException("row"); } bool flag2 = this.rows.Count + count > this.cells.RowCapacity; if (flag2) { throw new ArgumentOutOfRangeException("count"); } bool flag3 = count < 1; if (flag3) { throw new ArgumentException("count must be >= 1"); } bool flag4 = row >= this.rows.Count; if (flag4) { this.AppendRows(count); } else { Stopwatch stopwatch = Stopwatch.StartNew(); int num = (row == 0) ? 0 : this.rows[row - 1].Bottom; int num2 = num; ushort innerHeight = this.rows[row].InnerHeight; RowHeader[] array = new RowHeader[count]; for (int i = 0; i < count; i++) { array[i] = new RowHeader(this) { Row = row + i, Top = num, InnerHeight = innerHeight, InnerStyle = ((this.rows[row].InnerStyle == null) ? null : new WorksheetRangeStyle(this.rows[row].InnerStyle)), IsAutoHeight = true }; num += (int)innerHeight; } this.rows.InsertRange(row, array); int num3 = (int)innerHeight * count; for (int j = this.rows.Count - 1; j > row + count - 1; j--) { bool flag5 = j != this.rows.Count; if (flag5) { this.rows[j].Row += count; this.rows[j].Top += num3; } for (int k = this.cols.Count - 1; k >= 0; k--) { this.cells[j, k] = this.cells[j - count, k]; Cell cell = this.cells[j, k]; bool flag6 = cell != null; if (flag6) { cell.InternalRow += count; cell.Top += (float)num3; cell.TextBoundsTop += (float)num3; bool flag7 = !cell.MergeStartPos.IsEmpty && cell.MergeStartPos.Row >= row; if (flag7) { cell.MergeStartPos = cell.MergeStartPos.Offset(count, 0); } bool flag8 = !cell.MergeEndPos.IsEmpty; if (flag8) { cell.MergeEndPos = cell.MergeEndPos.Offset(count, 0); } } this.vBorders[j, k] = this.vBorders[j - count, k]; this.hBorders[j, k] = this.hBorders[j - count, k]; } } for (int l = row; l < row + count; l++) { for (int m = 0; m < this.cols.Count; m++) { this.hBorders[l, m] = null; this.vBorders[l, m] = null; this.cells[l, m] = null; } } for (int n = this.cols.Count; n >= 0; n--) { bool flag9 = row == 0; if (flag9) { this.cells[row, n] = null; } this.vBorders[row, n] = null; this.hBorders[row, n] = null; bool flag10 = row > 0 && this.vBorders[row - 1, n] != null && this.vBorders[row - 1, n].Style != null; bool flag11 = this.vBorders[row + count, n] != null && this.vBorders[row + count, n].Style != null; bool flag12 = flag10 && flag11; if (flag12) { this.SetVBorders(row, n, count, this.vBorders[row - 1, n].Style, this.vBorders[row - 1, n].Pos); } bool flag13 = n != this.cols.Count; if (flag13) { Cell cell2 = (row <= 0) ? null : this.cells[row - 1, n]; Cell cell3 = this.cells[row + count, n]; Cell cell4 = this.cells[row, n] = null; bool flag14 = cell2 != null && cell2.Rowspan != 1; bool flag15 = cell3 != null && cell3.Rowspan != 1; bool flag16 = Worksheet.IsInsideSameMergedCell(cell2, cell3); bool flag17 = flag16; if (flag17) { for (int num4 = row; num4 < row + count; num4++) { cell4 = this.CreateCell(num4, n, true); cell4.Colspan = 0; cell4.Rowspan = 0; cell4.MergeEndPos = cell2.MergeEndPos.Offset(count, 0); cell4.MergeStartPos = cell2.MergeStartPos; bool flag18 = n > cell4.MergeStartPos.Col; if (flag18) { this.vBorders[num4, n] = new ReoGridVBorder(); } this.hBorders[num4, n] = new ReoGridHBorder(); } for (int num5 = cell4.MergeStartPos.Row; num5 < row; num5++) { this.cells[num5, n].MergeEndPos = this.cells[num5, n].MergeEndPos.Offset(count, 0); } bool flag19 = n == cell4.MergeStartPos.Col; if (flag19) { Cell cell5 = this.GetCell(cell4.MergeStartPos); Cell cell6 = cell5; cell6.Rowspan += (short)count; cell5.Height += (float)num3; } } else { this.cells[row, n] = null; } } } OutlineCollection outlineCollection = this.GetOutlines(RowOrColumn.Row); bool flag20 = outlineCollection != null; if (flag20) { outlineCollection.IterateOutlines(delegate(ReoGridOutline o) { RangeModifyHelper.ProcessAfterInsertRow(row, count, (IRowRange)o); return true; }); } RangeModifyHelper.ProcessAfterInsertRow(row, count, this.printableRange); bool flag21 = this.drawingCanvas.drawingObjects != null; if (flag21) { foreach (IDrawingObject drawingObject in this.drawingCanvas.drawingObjects) { bool flag22 = drawingObject.Y >= (float)num2; if (flag22) { drawingObject.Y += (float)num3; } else { bool flag23 = drawingObject.Bottom > (float)num2; if (flag23) { drawingObject.Height += (float)num3; } } } } bool flag24 = row < this.FreezePos.Row; if (flag24) { this.FreezePos = this.FixPos(new CellPosition(this.FreezePos.Row + count, this.FreezePos.Col)); } this.UpdateViewportController(); EventHandler rowsInserted = this.RowsInserted; if (rowsInserted != null) { rowsInserted(this, new RowsInsertedEventArgs(row, count)); } stopwatch.Stop(); Debug.WriteLine("insert rows: " + stopwatch.ElapsedMilliseconds.ToString() + " ms."); } } public void InsertColumns(int col, int count) { bool flag = col > this.cols.Count; if (flag) { throw new ArgumentOutOfRangeException("col"); } bool flag2 = this.cols.Count + count > this.cells.ColCapacity; if (flag2) { throw new ArgumentOutOfRangeException("count"); } bool flag3 = count < 1; if (flag3) { throw new ArgumentException("count must be >= 1"); } bool flag4 = col >= this.cols.Count; if (flag4) { this.AppendColumns(count); } else { Stopwatch stopwatch = Stopwatch.StartNew(); int num = (col == 0) ? 0 : this.cols[col - 1].Right; ushort innerWidth = this.cols[col].InnerWidth; ColumnHeader[] array = new ColumnHeader[count]; int num2 = num; for (int i = 0; i < count; i++) { int num3 = col + i; array[i] = new ColumnHeader(this) { Col = num3, RenderText = RGUtility.GetAlphaChar((long)num3), Left = num, InnerWidth = innerWidth, InnerStyle = ((this.cols[col].InnerStyle == null) ? null : new WorksheetRangeStyle(this.cols[col].InnerStyle)), IsAutoWidth = true }; num += (int)innerWidth; } this.cols.InsertRange(col, array); int num4 = (int)innerWidth * count; for (int j = this.cols.Count - 1; j > col + count - 1; j--) { bool flag5 = j != this.cols.Count; if (flag5) { int num5 = this.cols[j].Col + count; this.cols[j].Col = num5; this.cols[j].Left += num4; bool flag6 = this.cols[j].Text == null; if (flag6) { this.cols[j].RenderText = RGUtility.GetAlphaChar((long)num5); } } for (int k = this.rows.Count - 1; k >= 0; k--) { this.cells[k, j] = this.cells[k, j - count]; Cell cell = this.cells[k, j]; bool flag7 = cell != null; if (flag7) { cell.InternalCol += count; cell.Left += (float)num4; cell.TextBoundsLeft += (float)num4; bool flag8 = !cell.MergeStartPos.IsEmpty && cell.MergeStartPos.Col >= col; if (flag8) { cell.MergeStartPos = cell.MergeStartPos.Offset(0, count); } bool flag9 = !cell.MergeEndPos.IsEmpty; if (flag9) { cell.MergeEndPos = cell.MergeEndPos.Offset(0, count); } } this.vBorders[k, j] = this.vBorders[k, j - count]; this.hBorders[k, j] = this.hBorders[k, j - count]; } } for (int l = col; l < col + count; l++) { for (int m = 0; m < this.rows.Count; m++) { this.hBorders[m, l] = null; this.vBorders[m, l] = null; this.cells[m, l] = null; } } for (int n = this.rows.Count; n >= 0; n--) { bool flag10 = col == 0; if (flag10) { this.cells[n, col] = null; } this.vBorders[n, col] = null; this.hBorders[n, col] = null; bool flag11 = col > 0 && this.hBorders[n, col - 1] != null && this.hBorders[n, col - 1].Style != null; bool flag12 = this.hBorders[n, col + count] != null && this.hBorders[n, col + count].Style != null; bool flag13 = flag11 && flag12; if (flag13) { this.SetHBorders(n, col, count, this.hBorders[n, col - 1].Style, this.hBorders[n, col - 1].Pos); } bool flag14 = n != this.rows.Count; if (flag14) { Cell cell2 = (col <= 0) ? null : this.cells[n, col - 1]; Cell cell3 = this.cells[n, col + count]; Cell cell4 = this.cells[n, col] = null; bool flag15 = cell2 != null && cell2.Rowspan != 1; bool flag16 = cell3 != null && cell3.Rowspan != 1; bool flag17 = Worksheet.IsInsideSameMergedCell(cell2, cell3); bool flag18 = flag17; if (flag18) { for (int num6 = col; num6 < col + count; num6++) { cell4 = this.CreateCell(n, num6, true); cell4.Colspan = 0; cell4.Rowspan = 0; cell4.MergeEndPos = cell2.MergeEndPos.Offset(0, count); cell4.MergeStartPos = cell2.MergeStartPos; bool flag19 = n > cell4.MergeStartPos.Row; if (flag19) { this.hBorders[n, num6] = new ReoGridHBorder(); } this.vBorders[n, num6] = new ReoGridVBorder(); } for (int num7 = cell4.MergeStartPos.Col; num7 < col; num7++) { this.cells[n, num7].MergeEndPos = this.cells[n, num7].MergeEndPos.Offset(0, count); } bool flag20 = n == cell4.MergeStartPos.Row; if (flag20) { Cell cell5 = this.GetCell(cell4.MergeStartPos); Cell cell6 = cell5; cell6.Colspan += (short)count; cell5.Width += (float)num4; } } else { this.cells[n, col] = null; } } } RangeModifyHelper.ProcessAfterInsertColumn(col, count, this.printableRange); OutlineCollection outlineCollection = this.GetOutlines(RowOrColumn.Column); bool flag21 = outlineCollection != null; if (flag21) { outlineCollection.IterateOutlines(delegate(ReoGridOutline o) { RangeModifyHelper.ProcessAfterInsertColumn(col, count, (IColumnRange)o); return true; }); } bool flag22 = this.drawingCanvas.drawingObjects != null; if (flag22) { foreach (IDrawingObject drawingObject in this.drawingCanvas.drawingObjects) { bool flag23 = drawingObject.Left >= (float)num2; if (flag23) { drawingObject.X += (float)num4; } else { bool flag24 = drawingObject.Right > (float)num2; if (flag24) { drawingObject.Width += (float)num4; } } } } bool flag25 = col < this.FreezePos.Col; if (flag25) { this.FreezePos = this.FixPos(new CellPosition(this.FreezePos.Row, this.FreezePos.Col + count)); } this.selectionRange = this.FixRange(this.selectionRange); this.UpdateViewportController(); EventHandler columnsInserted = this.ColumnsInserted; if (columnsInserted != null) { columnsInserted(this, new ColumnsInsertedEventArgs(col, count)); } stopwatch.Stop(); long elapsedMilliseconds = stopwatch.ElapsedMilliseconds; bool flag26 = elapsedMilliseconds > 15L; if (flag26) { Debug.WriteLine("insert cols: " + elapsedMilliseconds.ToString() + " ms."); } } } public void DeleteRows(int row, int count) { this.DeleteRows(row, count, null); } internal void DeleteRows(int row, int count, RemoveRowsAction action) { bool flag = row < 0 || row >= this.rows.Count; if (flag) { throw new ArgumentOutOfRangeException("count"); } bool flag2 = count >= this.rows.Count; if (flag2) { throw new ArgumentOutOfRangeException("count"); } bool flag3 = row + count > this.rows.Count; if (flag3) { throw new ArgumentOutOfRangeException("row + count, at least one row should be left"); } Stopwatch stopwatch = Stopwatch.StartNew(); int top = this.rows[row].Top; int endrow = row + count; int num = this.rows[endrow - 1].Bottom - this.rows[row].Top; float num2 = (float)num * this.renderScaleFactor; Debug.Assert(num > 0); int num3 = this.MaxContentRow + 1; int num4 = this.MaxContentCol + 1; this.suspendingUIUpdates = true; this.rows.RemoveRange(row, count); for (int i = row; i < this.rows.Count; i++) { this.rows[i].Row -= count; this.rows[i].Top -= num; Debug.Assert(this.rows[i].Row >= 0); } for (int j = 0; j <= this.cols.Count; j++) { Cell cell = this.cells[row, j]; bool flag4 = j < this.cols.Count && cell != null; if (flag4) { bool flag5 = !cell.MergeStartPos.IsEmpty && cell.MergeStartPos.Row < row; if (flag5) { bool flag6 = cell.MergeStartPos.Col == j; if (flag6) { Cell cell2 = this.cells[cell.MergeStartPos.Row, cell.MergeStartPos.Col]; Debug.Assert(cell2 != null); Debug.Assert(cell2.Colspan > 0); int num5 = Math.Min(count, cell.MergeEndPos.Row - row + 1); Cell cell3 = cell2; cell3.Rowspan -= (short)num5; Debug.Assert(cell2.Rowspan > 0); cell2.Height = (float)(this.rows[cell2.InternalRow + (int)cell2.Rowspan - 1].Bottom - this.rows[cell2.InternalRow].Top); } for (int k = cell.MergeStartPos.Row; k < row; k++) { Cell cell4 = this.cells[k, j]; int num6 = Math.Min(count, cell4.MergeEndPos.Row - row + 1); cell4.MergeEndPos = cell4.MergeEndPos.Offset(-num6, 0); } } } bool flag7 = row > 0 && this.vBorders[row - 1, j] != null && this.vBorders[row - 1, j].Span > 0; if (flag7) { int num7 = 0; bool flag8 = this.vBorders[endrow, j] != null && this.vBorders[endrow, j].Span + count + 1 != this.vBorders[row - 1, j].Span && this.vBorders[endrow, j].Style.Equals(this.vBorders[row - 1, j].Style) && this.vBorders[endrow, j].Pos == this.vBorders[row - 1, j].Pos; if (flag8) { num7 = this.vBorders[endrow, j].Span; } int num8 = 0; bool flag9 = this.vBorders[row, j] != null && this.vBorders[row, j].Span > 0 && this.vBorders[row, j].Span == this.vBorders[row - 1, j].Span - 1; if (flag9) { num8 = Math.Min(this.vBorders[row, j].Span, count); } int num9 = this.vBorders[row - 1, j].Span; this.vBorders[row - 1, j].Span += num7 - num8; bool flag10 = row > 1; if (flag10) { for (int l = row - 2; l >= 0; l--) { bool flag11 = this.vBorders[l, j] != null && this.vBorders[l, j].Span == num9 + 1; if (!flag11) { break; } this.vBorders[l, j].Span += num7 - num8; num9++; } } } } int num10 = Math.Min(this.rows.Count + count, this.rows.Capacity); for (int m = 0; m < this.cols.Count; m++) { for (int n = endrow; n < num10; n++) { Cell cell5 = this.cells[n, m]; bool flag12 = cell5 != null; if (flag12) { bool flag13 = cell5.MergeStartPos.Row >= endrow; if (flag13) { cell5.MergeStartPos = cell5.MergeStartPos.Offset(-count, 0); cell5.Top -= (float)num; cell5.TextBoundsTop -= num2; } else { bool flag14 = cell5.InternalRow >= endrow && cell5.IsValidCell; if (flag14) { cell5.Top -= (float)num; cell5.TextBoundsTop -= num2; } else { bool flag15 = cell5.MergeStartPos.Row >= row && cell5.MergeStartPos.Row < endrow; if (flag15) { bool flag16 = n == endrow && m == cell5.MergeStartPos.Col; if (flag16) { Cell cell6 = this.cells[cell5.MergeStartPos.Row, cell5.MergeStartPos.Col]; Debug.Assert(cell6 != null); cell5.Rowspan = (short)((int)cell6.Rowspan - endrow + cell5.MergeStartPos.Row); cell5.Colspan = (short)(cell5.MergeEndPos.Col - cell5.MergeStartPos.Col + 1); cell5.Bounds = this.GetRangeBounds(cell5.MergeStartPos.Row, m, (int)cell5.Rowspan, (int)cell5.Colspan); CellUtility.CopyCellContent(cell5, cell6); } cell5.MergeStartPos = new CellPosition(row, cell5.MergeStartPos.Col); } } } int num11 = Math.Min(count, cell5.MergeEndPos.Row - cell5.MergeStartPos.Row); cell5.MergeEndPos = cell5.MergeEndPos.Offset(-num11, 0); } } } for (int num12 = 0; num12 <= num4; num12++) { for (int num13 = row; num13 <= num3; num13++) { Cell cell7 = this.cells[num13 + count, num12]; this.cells[num13, num12] = cell7; bool flag17 = cell7 != null; if (flag17) { cell7.InternalRow -= count; } this.hBorders[num13, num12] = this.hBorders[num13 + count, num12]; this.vBorders[num13, num12] = this.vBorders[num13 + count, num12]; } bool flag18 = row == 0 || !this.IsInsideSameMergedCell(row - 1, num12, row, num12); if (flag18) { bool flag19 = this.hBorders[row, num12] != null && this.hBorders[row, num12].Span == 0; if (flag19) { this.hBorders[row, num12] = null; } } } OutlineCollection rowOutlines = this.GetOutlines(RowOrColumn.Row); bool flag20 = rowOutlines != null; if (flag20) { List removingOutlines = null; bool flag21 = action != null; if (flag21) { action.deletedOutlines = removingOutlines; } rowOutlines.IterateOutlines(delegate(ReoGridOutline o) { RangeModifyHelper.ProcessAfterDeleteRow(row, count, endrow, (IRowRange)o, delegate { bool flag40 = action != null; if (flag40) { bool flag41 = action.changedOutlines == null; if (flag41) { action.changedOutlines = new Dictionary(); } action.changedOutlines[o] = new BackupRangeInfo(o.Start, o.Count); } }, delegate { bool flag40 = removingOutlines == null; if (flag40) { removingOutlines = new List(); } removingOutlines.Add(o); }); return true; }); bool flag22 = removingOutlines != null; if (flag22) { bool flag23 = action != null; if (flag23) { action.deletedOutlines = removingOutlines; } foreach (IReoGridOutline outline in removingOutlines) { this.RemoveOutline(outline); } } List deletedOutlines2 = null; rowOutlines.IterateReverseOutlines(delegate(ReoGridOutline o) { bool flag40 = rowOutlines.HasSame(o, deletedOutlines2); if (flag40) { bool flag41 = deletedOutlines2 == null; if (flag41) { deletedOutlines2 = new List(); } deletedOutlines2.Add(o); } return true; }); bool flag24 = deletedOutlines2 != null; if (flag24) { bool flag25 = action != null; if (flag25) { bool flag26 = action.deletedOutlines == null; if (flag26) { action.deletedOutlines = deletedOutlines2; } else { action.deletedOutlines.AddRange(deletedOutlines2); } } foreach (IReoGridOutline outline2 in deletedOutlines2) { this.RemoveOutline(outline2); } } } List removedNamedRange = null; foreach (string key in this.registeredNamedRanges.Keys) { NamedRange range = this.registeredNamedRanges[key]; RangeModifyHelper.ProcessAfterDeleteRow(row, count, endrow, range, delegate { bool flag40 = action != null; if (flag40) { bool flag41 = action.changedNamedRange == null; if (flag41) { action.changedNamedRange = new Dictionary(); } action.changedNamedRange[range] = new BackupRangeInfo(range.Row, range.Rows); } }, delegate { bool flag40 = removedNamedRange == null; if (flag40) { removedNamedRange = new List(1); } removedNamedRange.Add(range); }); } bool flag27 = action != null; if (flag27) { action.deletedNamedRanges = removedNamedRange; } bool flag28 = removedNamedRange != null; if (flag28) { foreach (NamedRange namedRange in removedNamedRange) { this.UndefineNamedRange(namedRange.Name); } } for (int num14 = 0; num14 < this.highlightRanges.Count; num14++) { HighlightRange range = this.highlightRanges[num14]; RangeModifyHelper.ProcessAfterDeleteRow(row, count, endrow, range, delegate { bool flag40 = action != null; if (flag40) { bool flag41 = action.changedHighlightRanges == null; if (flag41) { action.changedHighlightRanges = new Dictionary(); } action.changedHighlightRanges[range] = new BackupRangeInfo(range.Row, range.Rows); } }, delegate { bool flag40 = action != null; if (flag40) { bool flag41 = action.deletedHighlightRanges == null; if (flag41) { action.deletedHighlightRanges = new List(); } action.deletedHighlightRanges.Add(range); } this.RemoveHighlightRange(range); }); } bool flag29 = this.drawingCanvas.drawingObjects != null; if (flag29) { foreach (IDrawingObject drawingObject in this.drawingCanvas.drawingObjects) { bool flag30 = drawingObject.Y >= (float)top; if (flag30) { drawingObject.Y -= (float)num; } else { bool flag31 = drawingObject.Bottom > (float)top; if (flag31) { float num15 = drawingObject.Height - (float)num; bool flag32 = num15 < 0f; if (flag32) { num15 = 0f; } drawingObject.Height = num15; } } } } bool flag33 = this.cells.MaxRow >= endrow; if (flag33) { this.cells.MaxRow -= count; } bool flag34 = this.hBorders.MaxRow >= endrow; if (flag34) { this.hBorders.MaxRow -= count; } bool flag35 = this.vBorders.MaxRow >= endrow; if (flag35) { this.vBorders.MaxRow -= count; } bool flag36 = row < this.FreezePos.Row; if (flag36) { this.FreezePos = this.FixPos(new CellPosition(this.FreezePos.Row - count, this.FreezePos.Col)); bool flag37 = this.FreezePos.Row < 1; if (flag37) { bool flag38 = this.rows.Count > 1; if (flag38) { this.FreezePos = new CellPosition(1, this.FreezePos.Col); } else { this.FreezePos = new CellPosition(0, this.FreezePos.Col); } } } this.suspendingUIUpdates = false; this.UpdateViewportController(); RangePosition rangePosition = this.FixRange(this.selectionRange); this.ApplyRangeSelection(rangePosition.StartPos, rangePosition.EndPos, false); stopwatch.Stop(); long elapsedMilliseconds = stopwatch.ElapsedMilliseconds; bool flag39 = elapsedMilliseconds > 20L; if (flag39) { Debug.WriteLine("delete rows takes " + elapsedMilliseconds.ToString() + " ms."); } EventHandler rowsDeleted = this.RowsDeleted; if (rowsDeleted != null) { rowsDeleted(this, new RowsDeletedEventArgs(row, count)); } } public void DeleteColumns(int col, int count) { this.DeleteColumns(col, count, null); } internal void DeleteColumns(int col, int count, RemoveColumnsAction action) { bool flag = col < 0 || col >= this.cols.Count; if (flag) { throw new ArgumentOutOfRangeException("count"); } bool flag2 = count >= this.cols.Count; if (flag2) { throw new ArgumentOutOfRangeException("count"); } bool flag3 = col + count > this.cols.Count; if (flag3) { throw new ArgumentOutOfRangeException("col + count, at least one column should be left"); } Stopwatch stopwatch = Stopwatch.StartNew(); int num = this.MaxContentRow + 1; int num2 = this.MaxContentCol + 1; int left = this.cols[col].Left; int endcol = col + count; int num3 = this.cols[endcol - 1].Right - this.cols[col].Left; float num4 = (float)num3 * this.renderScaleFactor; this.suspendingUIUpdates = true; this.cols.RemoveRange(col, count); for (int i = col; i < this.cols.Count; i++) { this.cols[i].Col -= count; this.cols[i].Left -= num3; bool flag4 = this.cols[i].Text == null; if (flag4) { this.cols[i].RenderText = RGUtility.GetAlphaChar((long)i); } Debug.Assert(this.cols[i].Col >= 0); } for (int j = 0; j <= this.rows.Count; j++) { Cell cell = this.cells[j, col]; bool flag5 = j < this.rows.Count && cell != null; if (flag5) { bool flag6 = !cell.MergeStartPos.IsEmpty && cell.MergeStartPos.Col < col; if (flag6) { bool flag7 = cell.MergeStartPos.Row == j; if (flag7) { Cell cell2 = this.cells[cell.MergeStartPos.Row, cell.MergeStartPos.Col]; Debug.Assert(cell2.Colspan > 0); int num5 = Math.Min(count, cell.MergeEndPos.Col - col + 1); Cell cell3 = cell2; cell3.Colspan -= (short)num5; cell2.Width = (float)(this.cols[cell2.InternalCol + (int)cell2.Colspan - 1].Right - this.cols[cell2.InternalCol].Left); Debug.Assert(cell2.Colspan > 0); } for (int k = cell.MergeStartPos.Col; k < col; k++) { Cell cell4 = this.cells[j, k]; int num6 = Math.Min(count, cell4.MergeEndPos.Col - col + 1); cell4.MergeEndPos = cell4.MergeEndPos.Offset(0, -num6); } } } bool flag8 = col > 0 && this.hBorders[j, col - 1] != null && this.hBorders[j, col - 1].Span > 0; if (flag8) { int num7 = 0; bool flag9 = this.hBorders[j, endcol] != null && this.hBorders[j, endcol].Span + count + 1 != this.hBorders[j, col - 1].Span && this.hBorders[j, endcol].Style.Equals(this.hBorders[j, col - 1].Style) && this.hBorders[j, endcol].Pos == this.hBorders[j, col - 1].Pos; if (flag9) { num7 = this.hBorders[j, endcol].Span; } int num8 = 0; bool flag10 = this.hBorders[j, col] != null && this.hBorders[j, col].Span > 0 && this.hBorders[j, col].Span == this.hBorders[j, col - 1].Span - 1; if (flag10) { num8 = Math.Min(this.hBorders[j, col].Span, count); } int num9 = this.hBorders[j, col - 1].Span; this.hBorders[j, col - 1].Span += num7 - num8; bool flag11 = col > 1; if (flag11) { for (int l = col - 2; l >= 0; l--) { bool flag12 = this.hBorders[j, l] != null && this.hBorders[j, l].Span == num9 + 1; if (!flag12) { break; } this.hBorders[j, l].Span += num7 - num8; num9++; } } } } int num10 = Math.Min(this.cols.Count + count, this.cols.Capacity); for (int m = 0; m < this.rows.Count; m++) { for (int n = endcol; n < num10; n++) { Cell cell5 = this.cells[m, n]; bool flag13 = cell5 != null; if (flag13) { bool flag14 = cell5.MergeStartPos.Col >= endcol; if (flag14) { cell5.MergeStartPos = cell5.MergeStartPos.Offset(0, -count); cell5.Left -= (float)num3; cell5.TextBoundsLeft -= num4; } else { bool flag15 = cell5.InternalCol >= endcol && cell5.IsValidCell; if (flag15) { cell5.Left -= (float)num3; cell5.TextBoundsLeft -= num4; } else { bool flag16 = cell5.MergeStartPos.Col >= col && cell5.MergeStartPos.Col < endcol; if (flag16) { bool flag17 = n == endcol && m == this.cells[m, n].MergeStartPos.Row; if (flag17) { Cell cell6 = this.cells[cell5.MergeStartPos.Row, cell5.MergeStartPos.Col]; Debug.Assert(cell6 != null); cell5.Rowspan = (short)(cell5.MergeEndPos.Row - cell5.MergeStartPos.Row + 1); cell5.Colspan = (short)((int)cell6.Colspan - endcol + cell5.MergeStartPos.Col); cell5.Bounds = this.GetRangeBounds(m, cell5.MergeStartPos.Col, (int)cell5.Rowspan, (int)cell5.Colspan); CellUtility.CopyCellContent(cell5, cell6); } cell5.MergeStartPos = new CellPosition(cell5.MergeStartPos.Row, col); } } } int num11 = Math.Min(count, cell5.MergeEndPos.Col - cell5.MergeStartPos.Col); cell5.MergeEndPos = cell5.MergeEndPos.Offset(0, -num11); } } } for (int num12 = 0; num12 <= num; num12++) { for (int num13 = col; num13 <= num2; num13++) { Cell cell7 = this.cells[num12, num13 + count]; this.cells[num12, num13] = cell7; bool flag18 = cell7 != null; if (flag18) { cell7.InternalCol -= count; } this.hBorders[num12, num13] = this.hBorders[num12, num13 + count]; this.vBorders[num12, num13] = this.vBorders[num12, num13 + count]; } bool flag19 = col == 0 || !this.IsInsideSameMergedCell(num12, col - 1, num12, col); if (flag19) { bool flag20 = this.vBorders[num12, col] != null && this.vBorders[num12, col].Span == 0; if (flag20) { this.vBorders[num12, col] = null; } } } OutlineCollection colOutlines = this.GetOutlines(RowOrColumn.Column); bool flag21 = colOutlines != null; if (flag21) { List removingOutlines = null; bool flag22 = action != null; if (flag22) { action.deletedOutlines = removingOutlines; } colOutlines.IterateOutlines(delegate(ReoGridOutline o) { RangeModifyHelper.ProcessAfterDeleteColumn(col, count, endcol, (IColumnRange)o, delegate { bool flag41 = action != null; if (flag41) { bool flag42 = action.changedOutlines == null; if (flag42) { action.changedOutlines = new Dictionary(); } action.changedOutlines[o] = new BackupRangeInfo(o.Start, o.Count); } }, delegate { bool flag41 = removingOutlines == null; if (flag41) { removingOutlines = new List(); } removingOutlines.Add(o); }); return true; }); bool flag23 = removingOutlines != null; if (flag23) { bool flag24 = action != null; if (flag24) { action.deletedOutlines = removingOutlines; } foreach (IReoGridOutline outline in removingOutlines) { this.RemoveOutline(outline); } } List deletedOutlines2 = null; colOutlines.IterateReverseOutlines(delegate(ReoGridOutline o) { bool flag41 = colOutlines.HasSame(o, deletedOutlines2); if (flag41) { bool flag42 = deletedOutlines2 == null; if (flag42) { deletedOutlines2 = new List(); } deletedOutlines2.Add(o); } return true; }); bool flag25 = deletedOutlines2 != null; if (flag25) { bool flag26 = action != null; if (flag26) { bool flag27 = action.deletedOutlines == null; if (flag27) { action.deletedOutlines = deletedOutlines2; } else { action.deletedOutlines.AddRange(deletedOutlines2); } } foreach (IReoGridOutline outline2 in deletedOutlines2) { this.RemoveOutline(outline2); } } } List removedNamedRange = null; foreach (string key in this.registeredNamedRanges.Keys) { NamedRange range = this.registeredNamedRanges[key]; RangeModifyHelper.ProcessAfterDeleteColumn(col, count, endcol, range, delegate { bool flag41 = action != null; if (flag41) { bool flag42 = action.changedNamedRange == null; if (flag42) { action.changedNamedRange = new Dictionary(); } action.changedNamedRange[range] = new BackupRangeInfo(range.Col, range.Cols); } }, delegate { bool flag41 = removedNamedRange == null; if (flag41) { removedNamedRange = new List(1); } removedNamedRange.Add(range); }); } bool flag28 = action != null; if (flag28) { action.deletedNamedRanges = removedNamedRange; } bool flag29 = removedNamedRange != null; if (flag29) { foreach (NamedRange namedRange in removedNamedRange) { this.UndefineNamedRange(namedRange.Name); } } for (int num14 = 0; num14 < this.highlightRanges.Count; num14++) { HighlightRange range = this.highlightRanges[num14]; RangeModifyHelper.ProcessAfterDeleteColumn(col, count, endcol, range, delegate { bool flag41 = action != null; if (flag41) { bool flag42 = action.changedHighlightRanges == null; if (flag42) { action.changedHighlightRanges = new Dictionary(); } action.changedHighlightRanges[range] = new BackupRangeInfo(range.Col, range.Cols); } }, delegate { bool flag41 = action != null; if (flag41) { bool flag42 = action.deletedHighlightRanges == null; if (flag42) { action.deletedHighlightRanges = new List(); } action.deletedHighlightRanges.Add(range); } this.RemoveHighlightRange(range); }); } bool flag30 = this.drawingCanvas.drawingObjects != null; if (flag30) { foreach (IDrawingObject drawingObject in this.drawingCanvas.drawingObjects) { bool flag31 = drawingObject.X >= (float)left; if (flag31) { drawingObject.X -= (float)num3; } else { bool flag32 = drawingObject.Right > (float)left; if (flag32) { float num15 = drawingObject.Width - (float)num3; bool flag33 = num15 < 0f; if (flag33) { num15 = 0f; } drawingObject.Width = num15; } } } } bool flag34 = this.cells.MaxCol >= endcol; if (flag34) { this.cells.MaxCol -= count; } bool flag35 = this.hBorders.MaxCol >= endcol; if (flag35) { this.hBorders.MaxCol -= count; } bool flag36 = this.vBorders.MaxCol >= endcol; if (flag36) { this.vBorders.MaxCol -= count; } bool flag37 = col < this.FreezePos.Col; if (flag37) { this.FreezePos = this.FixPos(new CellPosition(this.FreezePos.Col, this.FreezePos.Col - count)); bool flag38 = this.FreezePos.Col < 1; if (flag38) { bool flag39 = this.cols.Count > 1; if (flag39) { this.FreezePos = new CellPosition(this.FreezePos.Row, 1); } else { this.FreezePos = new CellPosition(this.FreezePos.Row, 0); } } } this.suspendingUIUpdates = false; this.UpdateViewportController(); RangePosition rangePosition = this.FixRange(this.selectionRange); this.ApplyRangeSelection(rangePosition.StartPos, rangePosition.EndPos, false); stopwatch.Stop(); long elapsedMilliseconds = stopwatch.ElapsedMilliseconds; bool flag40 = elapsedMilliseconds > 20L; if (flag40) { Debug.WriteLine("deleting columns takes " + elapsedMilliseconds.ToString() + " ms."); } EventHandler columnsDeleted = this.ColumnsDeleted; if (columnsDeleted != null) { columnsDeleted(this, new ColumnsDeletedEventArgs(col, count)); } } public void HideRows(int row, int count) { this.SetRowsHeight(row, count, 0); } public void ShowRows(int row, int count) { this.SetRowsHeight(row, count, delegate(int r) { RowHeader rowHeader = this.rows[r]; return (int)(rowHeader.IsVisible ? rowHeader.InnerHeight : rowHeader.LastHeight); }, true); } public void HideColumns(int col, int count) { this.SetColumnsWidth(col, count, 0); } public void ShowColumns(int col, int count) { this.SetColumnsWidth(col, count, delegate(int c) { ColumnHeader columnHeader = this.cols[c]; return (int)(columnHeader.IsVisible ? columnHeader.InnerWidth : columnHeader.LastWidth); }, true, true); } public bool IsRowVisible(int row) { bool flag = row < 0 || row >= this.RowCount; return !flag && this.rows[row].IsVisible; } public bool IsColumnVisible(int col) { bool flag = col < 0 || col >= this.ColumnCount; return !flag && this.cols[col].IsVisible; } public int ColumnCount { get { return this.cols.Count; } set { this.SetCols(value); } } public int RowCount { get { return this.rows.Count; } set { this.SetRows(value); } } internal RowHeader RetrieveRowHeader(int index) { return this.rows[index]; } internal ColumnHeader RetrieveColumnHeader(int index) { return this.cols[index]; } public RowHeader GetRowHeader(int index) { return (index < 0 || index >= this.rows.Count) ? null : this.rows[index]; } public ColumnHeader GetColumnHeader(int index) { return (index < 0 || index >= this.cols.Count) ? null : this.cols[index]; } public Worksheet.RowHeaderCollection RowHeaders { get { bool flag = this.rowHeaderCollection == null; if (flag) { this.rowHeaderCollection = new Worksheet.RowHeaderCollection(this); } return this.rowHeaderCollection; } } public Worksheet.ColumnHeaderCollection ColumnHeaders { get { bool flag = this.colHeaderCollection == null; if (flag) { this.colHeaderCollection = new Worksheet.ColumnHeaderCollection(this); } return this.colHeaderCollection; } } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler RowsInserted; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler RowsDeleted; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler ColumnsInserted; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler ColumnsDeleted; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler RowsHeightChanged; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler ColumnsWidthChanged; public RowOutlineCollection RowOutlines { get { bool flag = this.rowOutlineCollection == null; if (flag) { this.rowOutlineCollection = new RowOutlineCollection(this); } return this.rowOutlineCollection; } } public ColumnOutlineCollection ColumnOutlines { get { bool flag = this.columnOutlineCollection == null; if (flag) { this.columnOutlineCollection = new ColumnOutlineCollection(this); } return this.columnOutlineCollection; } } public OutlineCollection GetOutlines(RowOrColumn flag) { return (this.outlines == null) ? null : this.outlines[flag]; } public void IterateOutlines(RowOrColumn flag, Func, ReoGridOutline, bool> iterator) { bool flag2 = iterator == null; if (flag2) { throw new ArgumentNullException("iterator", "iterator cannot be null"); } OutlineCollection outlineCollection = null; bool flag3 = this.outlines != null && this.outlines.TryGetValue(flag, out outlineCollection); if (flag3) { foreach (OutlineGroup outlineGroup in outlineCollection) { foreach (ReoGridOutline arg in outlineGroup) { bool flag4 = !iterator(outlineGroup, arg); if (flag4) { return; } } } } } private static void InsertOutline(OutlineCollection outlineGroups, int groupIndex, ReoGridOutline outline) { bool flag = groupIndex < 0; if (flag) { outlineGroups.Insert(0, new OutlineGroup { outline }); } else { OutlineGroup outlineGroup = outlineGroups[groupIndex]; for (int i = 0; i < outlineGroup.Count; i++) { ReoGridOutline reoGridOutline = outlineGroup[i]; bool flag2 = reoGridOutline.Contains(outline); if (flag2) { outlineGroup.RemoveAt(i); Worksheet.InsertOutline(outlineGroups, groupIndex - 1, reoGridOutline); break; } } outlineGroup.Add(outline); } } public ReoGridOutline GroupColumns(int col, int count) { return this.AddOutline(RowOrColumn.Column, col, count); } public ReoGridOutline GroupRows(int row, int count) { return this.AddOutline(RowOrColumn.Row, row, count); } public ReoGridOutline AddOutline(RowOrColumn flag, int start, int count) { bool flag2 = flag == RowOrColumn.Both; ReoGridOutline result; if (flag2) { this.AddOutline(RowOrColumn.Column, start, count); result = this.AddOutline(RowOrColumn.Row, start, count); } else { int num = ((flag == RowOrColumn.Row) ? this.rows.Count : this.cols.Count) - 1; bool flag3 = start < 0 || start >= num; if (flag3) { throw new OutlineOutOfRangeException(start, count, "row"); } bool flag4 = count < 0 || start + count > num; if (flag4) { throw new OutlineOutOfRangeException(start, count, "count"); } bool flag5 = count == 0; if (flag5) { result = null; } else { bool flag6 = this.outlines == null; if (flag6) { this.outlines = new Dictionary> { { RowOrColumn.Row, new OutlineCollection() }, { RowOrColumn.Column, new OutlineCollection() } }; } OutlineCollection outlineCollection = this.outlines[flag]; bool flag7 = outlineCollection.Count >= 9; if (flag7) { throw new OutlineTooMuchException(); } int num2 = start + count; int groupIndex = outlineCollection.Count - 2; ReoGridOutline reoGridOutline = null; bool flag8 = false; bool flag9 = flag == RowOrColumn.Row; if (flag9) { reoGridOutline = new RowOutline(this, start, count); } else { reoGridOutline = new ColumnOutline(this, start, count); } for (int i = 0; i < outlineCollection.Count - 1; i++) { OutlineGroup outlineGroup = outlineCollection[i]; foreach (ReoGridOutline reoGridOutline2 in outlineGroup) { bool flag10 = start == reoGridOutline2.Start && num2 == reoGridOutline2.End; if (flag10) { throw new OutlineAlreadyDefinedException(); } bool flag11 = reoGridOutline.IntersectWith(reoGridOutline2); if (flag11) { throw new OutlineIntersectedException { Start = reoGridOutline2.Start, Count = reoGridOutline2.Count }; } bool flag12 = reoGridOutline.Contains(reoGridOutline2); if (flag12) { groupIndex = i - 1; flag8 = true; } } bool flag13 = flag8; if (flag13) { break; } } Worksheet.InsertOutline(outlineCollection, groupIndex, reoGridOutline); bool flag14 = this.viewportController != null; if (flag14) { bool flag15 = flag == RowOrColumn.Row; if (flag15) { bool flag16 = this.settings.Has(WorksheetSettings.View_AllowShowRowOutlines); if (flag16) { this.viewportController.SetViewVisible(ViewTypes.RowOutline, true); } } else { bool flag17 = this.settings.Has(WorksheetSettings.View_AllowShowColumnOutlines); if (flag17) { this.viewportController.SetViewVisible(ViewTypes.ColOutline, true); } } this.viewportController.UpdateController(); this.RequestInvalidate(); } bool flag18 = this.OutlineAdded != null; if (flag18) { this.OutlineAdded(this, new OutlineAddedEventArgs(reoGridOutline)); } result = reoGridOutline; } } return result; } public IReoGridOutline GetOutline(RowOrColumn flag, int start, int count) { ReoGridOutline reoGridOutline = null; OutlineCollection outlineCollection = this.outlines[flag]; Func callFunc = null; foreach (OutlineGroup outlineGroup in outlineCollection) { IEnumerable source = outlineGroup; Func predicate; if ((predicate = callFunc) == null) { predicate = (callFunc = ((ReoGridOutline o) => o.Start == start && o.Count == count)); } reoGridOutline = source.FirstOrDefault(predicate); bool flag2 = reoGridOutline != null; if (flag2) { break; } } return reoGridOutline; } public IReoGridOutline CollapseOutline(RowOrColumn flag, int start, int count) { IReoGridOutline outline = this.GetOutline(flag, start, count); outline.Collapse(); return outline; } public IReoGridOutline ExpandOutline(RowOrColumn flag, int start, int count) { IReoGridOutline outline = this.GetOutline(flag, start, count); outline.Expand(); return outline; } private static void RearrangementOutline(OutlineCollection outlineGroups, int startGroup) { bool flag = startGroup >= outlineGroups.Count - 1 || startGroup < 1; if (!flag) { OutlineGroup outlineGroup = outlineGroups[startGroup]; for (;;) { IL_26: for (int i = 0; i < outlineGroup.Count; i++) { ReoGridOutline or = outlineGroup[i]; OutlineGroup outlineGroup2 = outlineGroups[startGroup - 1]; ReoGridOutline reoGridOutline = outlineGroup2.FirstOrDefault((ReoGridOutline _o) => (_o.Start <= or.Start && _o.Count >= or.Start) || (_o.Start <= or.End && _o.End >= or.End)); bool flag2 = reoGridOutline == null; if (flag2) { outlineGroup.RemoveAt(i); outlineGroup2.Add(or); bool flag3 = outlineGroup.Count == 0; if (flag3) { outlineGroups.RemoveAt(startGroup); Worksheet.RearrangementOutline(outlineGroups, startGroup); } else { Worksheet.RearrangementOutline(outlineGroups, startGroup + 1); } goto IL_26; } } break; } } } public IReoGridOutline RemoveOutline(RowOrColumn flag, int start, int count) { IReoGridOutline outline = this.GetOutline(flag, start, count); bool flag2 = outline != null; if (flag2) { this.RemoveOutline(outline); } return outline; } public bool RemoveOutline(IReoGridOutline outline) { RowOrColumn rowOrColumn = (outline is RowOutline) ? RowOrColumn.Row : RowOrColumn.Column; OutlineCollection outlineCollection = this.GetOutlines(rowOrColumn); bool flag = outlineCollection == null; bool result; if (flag) { result = false; } else { bool flag2 = false; for (int i = 0; i < outlineCollection.Count - 1; i++) { OutlineGroup outlineGroup = outlineCollection[i]; for (int j = 0; j < outlineGroup.Count; j++) { ReoGridOutline reoGridOutline = outlineGroup[j]; bool flag3 = reoGridOutline == outline; if (flag3) { outlineGroup.Remove(reoGridOutline); Worksheet.RearrangementOutline(outlineCollection, i + 1); bool flag4 = outlineGroup.Count == 0; if (flag4) { outlineCollection.RemoveAt(i); } flag2 = true; break; } } bool flag5 = flag2; if (flag5) { break; } } bool flag6 = flag2; if (flag6) { bool flag7 = this.viewportController != null; if (flag7) { bool flag8 = outlineCollection.Count <= 1; if (flag8) { this.viewportController.SetViewVisible((rowOrColumn == RowOrColumn.Row) ? ViewTypes.RowOutline : ViewTypes.ColOutline, false); } this.UpdateViewportController(); } this.RequestInvalidate(); bool flag9 = this.OutlineRemoved != null; if (flag9) { this.OutlineRemoved(this, new OutlineRemovedEventArgs(outline)); } } result = flag2; } return result; } public void UngroupRows(int row, int count) { this.RemoveOutline(RowOrColumn.Row, row, count); } public void UngroupColumns(int col, int count) { this.RemoveOutline(RowOrColumn.Column, col, count); } public void UngroupAllRows() { bool flag = this.outlines == null; if (!flag) { OutlineCollection outlineCollection = this.outlines[RowOrColumn.Row]; bool flag2 = outlineCollection != null; if (flag2) { outlineCollection.Reset(); bool flag3 = this.viewportController != null; if (flag3) { this.viewportController.SetViewVisible(ViewTypes.RowOutline, false); this.UpdateViewportController(); this.RequestInvalidate(); } } } } public void UngroupAllColumns() { bool flag = this.outlines == null; if (!flag) { OutlineCollection outlineCollection = this.outlines[RowOrColumn.Column]; bool flag2 = outlineCollection != null; if (flag2) { outlineCollection.Reset(); bool flag3 = this.viewportController != null; if (flag3) { this.viewportController.SetViewVisible(ViewTypes.ColOutline, false); this.UpdateViewportController(); this.RequestInvalidate(); } } } } internal void ClearOutlines(RowOrColumn flag) { bool flag2 = this.outlines == null; if (!flag2) { ViewTypes viewTypes = ViewTypes.None; bool flag3 = (flag & RowOrColumn.Row) == RowOrColumn.Row; if (flag3) { this.outlines[RowOrColumn.Row].Reset(); viewTypes |= ViewTypes.RowOutline; } bool flag4 = (flag & RowOrColumn.Column) == RowOrColumn.Column; if (flag4) { this.outlines[RowOrColumn.Column].Reset(); viewTypes |= ViewTypes.ColOutline; } bool flag5 = this.viewportController != null; if (flag5) { this.viewportController.SetViewVisible(viewTypes, false); this.viewportController.UpdateController(); } } } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler OutlineAdded; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler OutlineRemoved; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler BeforeOutlineCollapse; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler AfterOutlineCollapse; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler BeforeOutlineExpand; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler AfterOutlineExpand; internal void RaiseBeforeOutlineCollapseEvent(BeforeOutlineCollapseEventArgs arg) { bool flag = this.BeforeOutlineCollapse != null; if (flag) { this.BeforeOutlineCollapse(this, arg); } } internal void RaiseAfterOutlineCollapseEvent(AfterOutlineCollapseEventArgs arg) { bool flag = this.AfterOutlineCollapse != null; if (flag) { this.AfterOutlineCollapse(this, arg); } } internal void RaiseBeforeOutlineExpandEvent(BeforeOutlineExpandingEventArgs arg) { bool flag = this.BeforeOutlineExpand != null; if (flag) { this.BeforeOutlineExpand(this, arg); } } internal void RaiseAfterOutlineExpandEvent(AfterOutlineExpandingEventArgs arg) { bool flag = this.AfterOutlineExpand != null; if (flag) { this.AfterOutlineExpand(this, arg); } } public PartialGrid GetPartialGrid(string addressOrName) { bool flag = RangePosition.IsValidAddress(addressOrName); PartialGrid partialGrid; if (flag) { partialGrid = this.GetPartialGrid(new RangePosition(addressOrName)); } else { NamedRange namedRange; bool flag2 = this.TryGetNamedRange(addressOrName, out namedRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } partialGrid = this.GetPartialGrid(namedRange.Position); } return partialGrid; } public PartialGrid GetPartialGrid(int row, int col, int rows, int cols) { return this.GetPartialGrid(new RangePosition(row, col, rows, cols)); } public PartialGrid GetPartialGrid(RangePosition range) { return this.GetPartialGrid(range, PartialGridCopyFlag.All, ExPartialGridCopyFlag.BorderOutsideOwner, false); } internal PartialGrid GetPartialGrid(RangePosition range, PartialGridCopyFlag flag, ExPartialGridCopyFlag exFlag, bool checkIntersectedRange = false) { range = this.FixRange(range); if (checkIntersectedRange) { RangePosition rangePosition = this.CheckIntersectedMergingRange(range); bool flag2 = rangePosition != RangePosition.Empty; if (flag2) { throw new RangeIntersectionException(rangePosition); } } int rows = range.Rows; int cols = range.Cols; PartialGrid data = new PartialGrid { Columns = cols, Rows = rows }; bool flag3 = (flag & PartialGridCopyFlag.CellData) == PartialGridCopyFlag.CellData || (flag & PartialGridCopyFlag.CellStyle) == PartialGridCopyFlag.CellStyle; if (flag3) { data.Cells = new Index4DArray(); for (int i = range.Row; i <= range.EndRow; i++) { for (int j = range.Col; j <= range.EndCol; j++) { Cell cell = this.cells[i, j]; int row = i - range.Row; int col = j - range.Col; Cell cell2 = null; bool flag4 = cell != null; if (flag4) { cell2 = new Cell(this); CellUtility.CopyCell(cell2, cell); } else { StyleParentKind styleParentKind = StyleParentKind.Own; WorksheetRangeStyle worksheetRangeStyle = StyleUtility.FindCellParentStyle(this, i, j, out styleParentKind); worksheetRangeStyle = StyleUtility.DistinctStyle(worksheetRangeStyle, Worksheet.DefaultStyle); bool flag5 = worksheetRangeStyle != null; if (flag5) { cell2 = new Cell(this); cell2.Colspan = 1; cell2.Rowspan = 1; cell2.InnerStyle = worksheetRangeStyle; cell2.StyleParentKind = StyleParentKind.Own; } } bool flag6 = cell2 != null; if (flag6) { data.Cells[row, col] = cell2; } } } } bool flag7 = (flag & PartialGridCopyFlag.HBorder) == PartialGridCopyFlag.HBorder; if (flag7) { data.HBorders = new Index4DArray(); this.hBorders.Iterate(range.Row, range.Col, rows + 1, cols, true, delegate(int r, int c, ReoGridHBorder hBorder) { bool flag9 = (exFlag & ExPartialGridCopyFlag.BorderOutsideOwner) == ExPartialGridCopyFlag.BorderOutsideOwner || (hBorder != null && hBorder.Pos == HBorderOwnerPosition.None) || ((r != range.Row || (hBorder != null && (hBorder.Pos & HBorderOwnerPosition.Top) == HBorderOwnerPosition.Top)) && (r != range.EndRow + 1 || (hBorder != null && (hBorder.Pos & HBorderOwnerPosition.Bottom) == HBorderOwnerPosition.Bottom))); if (flag9) { int num = c - range.Col; ReoGridHBorder reoGridHBorder = ReoGridHBorder.Clone(hBorder); bool flag10 = reoGridHBorder != null && reoGridHBorder.Span > cols - num; if (flag10) { reoGridHBorder.Span = cols - num; } data.HBorders[r - range.Row, num] = reoGridHBorder; } return 1; }); } bool flag8 = (flag & PartialGridCopyFlag.VBorder) == PartialGridCopyFlag.VBorder; if (flag8) { data.VBorders = new Index4DArray(); this.vBorders.Iterate(range.Row, range.Col, rows, cols + 1, true, delegate(int r, int c, ReoGridVBorder vBorder) { bool flag9 = (exFlag & ExPartialGridCopyFlag.BorderOutsideOwner) == ExPartialGridCopyFlag.BorderOutsideOwner || (vBorder != null && vBorder.Pos == VBorderOwnerPosition.None) || ((c != range.Col || (vBorder != null && (vBorder.Pos & VBorderOwnerPosition.Left) == VBorderOwnerPosition.Left)) && (c != range.EndCol + 1 || (vBorder != null && (vBorder.Pos & VBorderOwnerPosition.Right) == VBorderOwnerPosition.Right))); if (flag9) { int num = r - range.Row; ReoGridVBorder reoGridVBorder = ReoGridVBorder.Clone(vBorder); bool flag10 = reoGridVBorder != null && reoGridVBorder.Span > rows - num; if (flag10) { reoGridVBorder.Span = rows - num; } data.VBorders[num, c - range.Col] = reoGridVBorder; } return 1; }); } return data; } public RangePosition SetPartialGrid(string addressOrName, PartialGrid data) { bool flag = RangePosition.IsValidAddress(addressOrName); RangePosition result; if (flag) { result = this.SetPartialGrid(new RangePosition(addressOrName), data); } else { NamedRange namedRange; bool flag2 = this.TryGetNamedRange(addressOrName, out namedRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } result = this.SetPartialGrid(namedRange.Position, data); } return result; } public RangePosition SetPartialGrid(RangePosition toRange, PartialGrid data) { return this.SetPartialGrid(toRange, data, PartialGridCopyFlag.All, ExPartialGridCopyFlag.None); } internal RangePosition SetPartialGrid(RangePosition toRange, PartialGrid data, PartialGridCopyFlag flag) { return this.SetPartialGrid(toRange, data, flag, ExPartialGridCopyFlag.None); } internal RangePosition SetPartialGrid(RangePosition toRange, PartialGrid data, PartialGridCopyFlag flag, ExPartialGridCopyFlag exFlag) { bool isEmpty = toRange.IsEmpty; RangePosition result; if (isEmpty) { result = toRange; } else { toRange = this.FixRange(toRange); int num = data.Rows; int num2 = data.Columns; bool flag2 = num + toRange.Row > this.rows.Count; if (flag2) { num = this.rows.Count - toRange.Row; } bool flag3 = num2 + toRange.Col > this.cols.Count; if (flag3) { num2 = this.cols.Count - toRange.Col; } bool flag4 = (flag & PartialGridCopyFlag.CellData) == PartialGridCopyFlag.CellData || (flag & PartialGridCopyFlag.CellStyle) == PartialGridCopyFlag.CellStyle; if (flag4) { for (int i = 0; i < num; i++) { int j = 0; while (j < num2) { Cell cell = (data.Cells == null) ? null : data.Cells[i, j]; int num3 = toRange.Row + i; int num4 = toRange.Col + j; bool flag5 = false; bool flag6 = cell != null; if (flag6) { bool flag7 = !cell.MergeStartPos.IsEmpty && cell.MergeStartPos.Col < toRange.Col && cell.InternalCol - cell.MergeStartPos.Col > num4 - toRange.Col && cell.MergeEndPos.Col <= toRange.EndCol; if (flag7) { Cell cell2 = this.CreateAndGetCell(cell.MergeStartPos); cell2.MergeEndPos = new CellPosition(cell2.MergeEndPos.Row, num4); cell2.Colspan = (short)(num4 - cell2.InternalCol + 1); for (int k = cell2.InternalCol; k < cell2.InternalCol + (int)cell2.Colspan; k++) { Cell cell3 = this.cells[num3, k]; bool flag8 = cell3 != null; if (flag8) { cell3.MergeEndPos = new CellPosition(cell3.MergeEndPos.Row, num4); } } Cell cell4 = this.CreateAndGetCell(num3, num4); cell4.MergeStartPos = cell2.InternalPos; cell4.MergeEndPos = new CellPosition(cell2.MergeEndPos.Row, num4); cell4.Colspan = 0; cell4.Rowspan = 0; bool isEndMergedCell = cell4.IsEndMergedCell; if (isEndMergedCell) { cell2.Bounds = this.GetRangePhysicsBounds(new RangePosition(cell2.InternalPos, cell2.MergeEndPos)); } flag5 = true; } else { bool flag9 = !cell.MergeEndPos.IsEmpty && toRange.ContainsRow(cell.Row) && cell.MergeEndPos.Col > toRange.EndCol && cell.MergeStartPos.Col <= toRange.EndCol; if (flag9) { int num5 = Math.Min(cell.MergeEndPos.Col, this.cols.Count - 1); Cell cell5 = this.CreateAndGetCell(num3, num4); cell5.MergeStartPos = new CellPosition(cell.MergeStartPos.Row, cell.MergeStartPos.Col + num4 - cell.InternalCol); cell5.MergeEndPos = new CellPosition(cell.MergeEndPos.Row, num5); for (int l = toRange.EndCol + 1; l <= num5; l++) { Cell cell6 = this.CreateAndGetCell(num3, l); cell6.MergeStartPos = cell5.MergeStartPos; cell6.Rowspan = 0; cell6.Colspan = 0; } bool isStartMergedCell = cell5.IsStartMergedCell; if (isStartMergedCell) { cell5.Rowspan = (short)(cell5.MergeEndPos.Row - cell5.MergeStartPos.Row + 1); cell5.Colspan = (short)(cell5.MergeEndPos.Col - cell5.MergeStartPos.Col + 1); cell5.Bounds = this.GetRangeBounds(cell5.InternalPos, cell5.MergeEndPos); CellUtility.CopyCellContent(cell5, cell); this.UpdateCellFont(cell5, UpdateFontReason.FontChanged); } else { cell5.Rowspan = 0; cell5.Colspan = 0; } flag5 = true; } else { bool flag10 = !cell.MergeStartPos.IsEmpty && cell.MergeStartPos.Row < toRange.Row && cell.InternalRow - cell.MergeStartPos.Row > num3 - toRange.Row && cell.MergeEndPos.Row <= toRange.EndRow; if (flag10) { Cell cell7 = this.CreateAndGetCell(cell.MergeStartPos); cell7.Rowspan = (short)(num3 - cell7.InternalRow + 1); for (int m = cell.MergeStartPos.Row; m < num3; m++) { Cell cell8 = this.CreateAndGetCell(m, num4); cell8.MergeEndPos = new CellPosition(num3, cell.MergeEndPos.Col); } Cell cell9 = this.CreateAndGetCell(num3, num4); cell9.MergeStartPos = cell7.InternalPos; cell9.MergeEndPos = new CellPosition(num3, cell.MergeEndPos.Col); cell9.Rowspan = 0; cell9.Colspan = 0; bool isEndMergedCell2 = cell9.IsEndMergedCell; if (isEndMergedCell2) { cell7.Bounds = this.GetRangeBounds(cell7.InternalPos, cell7.MergeEndPos); } flag5 = true; } else { bool flag11 = !cell.MergeEndPos.IsEmpty && toRange.ContainsColumn(cell.Column) && cell.MergeEndPos.Row > toRange.EndRow && cell.MergeStartPos.Row <= toRange.EndRow; if (flag11) { int num6 = Math.Min(cell.MergeEndPos.Row, this.rows.Count - 1); for (int n = toRange.EndRow + 1; n <= num6; n++) { Cell cell10 = this.CreateAndGetCell(n, num4); cell10.MergeStartPos = new CellPosition(cell.MergeStartPos.Row, cell10.MergeStartPos.Col); cell10.Rowspan = 0; cell10.Colspan = 0; } Cell cell11 = this.CreateAndGetCell(num3, num4); cell11.MergeStartPos = cell.MergeStartPos; cell11.MergeEndPos = new CellPosition(num6, cell.MergeEndPos.Col); bool isStartMergedCell2 = cell11.IsStartMergedCell; if (isStartMergedCell2) { cell11.Rowspan = (short)(cell11.MergeEndPos.Row - cell11.MergeStartPos.Row + 1); cell11.Colspan = (short)(cell11.MergeEndPos.Col - cell11.MergeStartPos.Col + 1); cell11.Bounds = this.GetRangeBounds(cell11.InternalPos, cell11.MergeEndPos); CellUtility.CopyCellContent(cell11, cell); this.UpdateCellFont(cell11, UpdateFontReason.FontChanged); } else { cell11.Rowspan = 0; cell11.Colspan = 0; } flag5 = true; } } } } } bool flag12 = !flag5; if (flag12) { Cell cell12 = this.CreateAndGetCell(num3, num4); bool flag13 = cell12.Rowspan == 0 && cell12.Colspan == 0; if (!flag13) { bool flag14 = cell != null; if (flag14) { bool flag15 = (flag & PartialGridCopyFlag.CellData) == PartialGridCopyFlag.CellData; if (flag15) { CellUtility.CopyCellContent(cell12, cell); } bool flag16 = (flag & PartialGridCopyFlag.CellFormula) == PartialGridCopyFlag.CellFormula; if (flag16) { bool hasFormula = cell.HasFormula; if (hasFormula) { bool flag17 = cell.formulaTree == null; if (flag17) { try { cell.formulaTree = Parser.Parse(this.workbook, cell, cell.InnerFormula); } catch { cell.formulaStatus = FormulaStatus.SyntaxError; } } bool flag18 = cell.formulaTree != null; if (flag18) { ReplacableString rs = new ReplacableString(cell.InnerFormula); Stack> dirtyCells = new Stack>(); FormulaRefactor.CopyFormula(cell.Position, cell.formulaTree, cell12, rs, dirtyCells); } cell12.FontDirty = true; } } else { cell12.InnerFormula = null; } bool flag19 = cell12.Rowspan == 1 && cell12.Colspan == 1; if (flag19) { cell12.Rowspan = cell.Rowspan; cell12.Colspan = cell.Colspan; bool flag20 = !cell.MergeStartPos.IsEmpty; if (flag20) { cell12.MergeStartPos = cell.MergeStartPos.Offset(num3 - cell.InternalRow, num4 - cell.InternalCol); Debug.Assert(cell12.MergeStartPos.Row >= 0 && cell12.MergeStartPos.Row < this.rows.Count); Debug.Assert(cell12.MergeStartPos.Col >= 0 && cell12.MergeStartPos.Col < this.cols.Count); } bool flag21 = !cell.MergeEndPos.IsEmpty; if (flag21) { cell12.MergeEndPos = cell.MergeEndPos.Offset(num3 - cell.InternalRow, num4 - cell.InternalCol); Debug.Assert(cell12.MergeEndPos.Row >= 0 && cell12.MergeEndPos.Row < this.rows.Count); Debug.Assert(cell12.MergeEndPos.Col >= 0 && cell12.MergeEndPos.Col < this.cols.Count); } } else { this.UpdateCellFont(cell12, UpdateFontReason.FontChanged); } bool flag22 = (flag & PartialGridCopyFlag.CellStyle) == PartialGridCopyFlag.CellStyle && cell.InnerStyle != null; if (flag22) { bool flag23 = cell.StyleParentKind == StyleParentKind.Own; if (flag23) { cell12.InnerStyle = new WorksheetRangeStyle(cell.InnerStyle); } else { cell12.InnerStyle = cell.InnerStyle; } cell12.StyleParentKind = cell.StyleParentKind; bool flag24 = cell.InnerStyle.HAlign == ReoGridHorAlign.General; if (flag24) { cell12.RenderHorAlign = cell.RenderHorAlign; } } bool isEndMergedCell3 = cell12.IsEndMergedCell; if (isEndMergedCell3) { Cell cell13 = this.GetCell(cell12.MergeStartPos); Debug.Assert(cell13 != null); this.UpdateCellBounds(cell13); } else { bool flag25 = cell12.Rowspan == 1 && cell12.Colspan == 1; if (flag25) { this.UpdateCellFont(cell12, UpdateFontReason.FontChanged); } } } else { this.cells[num3, num4] = null; } } } IL_BD1: j++; continue; goto IL_BD1; } } } bool flag26 = (flag & PartialGridCopyFlag.HBorder) == PartialGridCopyFlag.HBorder; if (flag26) { bool flag27 = data.HBorders == null; if (flag27) { bool flag28 = toRange.Col > 0; if (flag28) { for (int num7 = toRange.Row; num7 <= toRange.EndRow; num7++) { this.CutBeforeHBorder(num7, toRange.Col); } } this.hBorders.Iterate(toRange.Row, toRange.Col, num, num2, true, delegate(int r, int c, ReoGridHBorder fromHBorder) { this.hBorders[r, c] = null; return 1; }); } else { for (int num8 = 0; num8 < num + 1; num8++) { for (int num9 = 0; num9 < num2; num9++) { int row = toRange.Row + num8; int col = toRange.Col + num9; this.CutBeforeHBorder(row, col); ReoGridHBorder reoGridHBorder = data.HBorders[num8, num9]; bool flag29 = reoGridHBorder == null; if (flag29) { this.hBorders[row, col] = null; } else { RangeBorderStyle style = reoGridHBorder.Style; int num10 = reoGridHBorder.Span; bool flag30 = num10 > num2 - num9; if (flag30) { num10 = num2 - num9; } this.GetHBorder(row, col).Span = num10; bool flag31 = data.HBorders[num8, num9].Style != null; if (flag31) { this.SetHBorders(row, col, num10, style, reoGridHBorder.Pos); } else { this.hBorders[row, col].Style = RangeBorderStyle.Empty; } } } } } } bool flag32 = (flag & PartialGridCopyFlag.VBorder) == PartialGridCopyFlag.VBorder; if (flag32) { bool flag33 = data.VBorders == null; if (flag33) { bool flag34 = toRange.Row > 0; if (flag34) { for (int num11 = toRange.Col; num11 <= toRange.EndCol; num11++) { this.CutBeforeVBorder(toRange.Row, num11); } } this.vBorders.Iterate(toRange.Row, toRange.Col, num, num2, true, delegate(int r, int c, ReoGridVBorder fromVBorder) { this.vBorders[r, c] = null; return 1; }); } else { for (int num12 = 0; num12 < num; num12++) { for (int num13 = 0; num13 < num2 + 1; num13++) { int row2 = toRange.Row + num12; int col2 = toRange.Col + num13; this.CutBeforeVBorder(row2, col2); ReoGridVBorder reoGridVBorder = data.VBorders[num12, num13]; bool flag35 = reoGridVBorder == null; if (flag35) { this.vBorders[row2, col2] = null; } else { RangeBorderStyle style2 = reoGridVBorder.Style; int num14 = reoGridVBorder.Span; bool flag36 = num14 > num - num12; if (flag36) { num14 = num - num12; } this.GetVBorder(row2, col2).Span = num14; bool flag37 = data.VBorders[num12, num13].Style != null; if (flag37) { this.SetVBorders(row2, col2, num14, style2, reoGridVBorder.Pos); } else { this.vBorders[row2, col2].Style = RangeBorderStyle.Empty; } } } } } } result = new RangePosition(toRange.Row, toRange.Col, num, num2); } return result; } public RangePosition SetPartialGridRepeatly(string addressOrName, PartialGrid grid) { bool flag = RangePosition.IsValidAddress(addressOrName); RangePosition result; if (flag) { result = this.SetPartialGridRepeatly(new RangePosition(addressOrName), grid); } else { NamedRange namedRange; bool flag2 = this.TryGetNamedRange(addressOrName, out namedRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } result = this.SetPartialGridRepeatly(namedRange.Position, grid); } return result; } public RangePosition SetPartialGridRepeatly(RangePosition range, PartialGrid grid) { bool flag = grid.Rows <= 0 || grid.Columns <= 0; RangePosition result; if (flag) { result = RangePosition.Empty; } else { for (int i = range.Row; i <= range.EndRow; i += grid.Rows) { for (int j = range.Col; j <= range.EndCol; j += grid.Columns) { this.SetPartialGrid(new RangePosition(i, j, grid.Rows, grid.Columns), grid); } } result = range; } return result; } public PrintSettings PrintSettings { get { bool flag = this.printSettings == null; if (flag) { this.printSettings = new PrintSettings(); } return this.printSettings; } set { this.printSettings = value; bool flag = !this.printableRange.IsEmpty; if (flag) { this.AutoSplitPage(); } } } public RangePosition PrintableRange { get { return this.printableRange; } set { value = this.FixRange(value); bool isEmpty = value.IsEmpty; if (isEmpty) { this.userPageBreakCols.Clear(); this.userPageBreakRows.Clear(); } else { bool flag = this.printableRange != value; if (flag) { this.printableRange = value; bool flag2 = this.userPageBreakCols != null; if (flag2) { for (int i = 0; i < this.userPageBreakCols.Count; i++) { bool flag3 = this.userPageBreakCols[i] < this.printableRange.Col; if (flag3) { this.userPageBreakCols.RemoveAt(i); } else { bool flag4 = this.userPageBreakCols[i] > this.printableRange.EndCol + 1; if (flag4) { this.userPageBreakCols.RemoveAt(i); } } } } bool flag5 = this.userPageBreakRows != null; if (flag5) { for (int j = 0; j < this.userPageBreakRows.Count; j++) { bool flag6 = this.userPageBreakRows[j] < this.printableRange.Row; if (flag6) { this.userPageBreakRows.RemoveAt(j); } else { bool flag7 = this.userPageBreakRows[j] > this.printableRange.EndRow + 1; if (flag7) { this.userPageBreakRows.RemoveAt(j); } } } } this.RaisePrintableRangeChangedEvent(); } } } } public Worksheet.RowPageBreakIndexCollection RowPageBreaks { get { bool flag = this.pageBreakRowCollection == null; if (flag) { this.pageBreakRowCollection = new Worksheet.RowPageBreakIndexCollection(this); } return this.pageBreakRowCollection; } } public Worksheet.ColumnPageBreakIndexCollection ColumnPageBreaks { get { bool flag = this.pageBreakColumnCollection == null; if (flag) { this.pageBreakColumnCollection = new Worksheet.ColumnPageBreakIndexCollection(this); } return this.pageBreakColumnCollection; } } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler PrintableRangeChanged; public void ResetAllPageBreaks() { this.printableRange = RangePosition.Empty; this.ClearUserPageBreaks(); this.AutoSplitPage(); } public void AutoSplitPage() { bool flag = this.MaxContentRow < 0 || this.MaxContentCol < 0; if (flag) { throw new NoPrintableContentException("No printable content found on this spreadsheet."); } Stopwatch stopwatch = Stopwatch.StartNew(); bool flag2 = this.printSettings == null; if (flag2) { this.printSettings = new PrintSettings(); } bool flag3 = this.pageBreakRows == null; if (flag3) { this.pageBreakRows = new List(); } else { this.pageBreakRows.Clear(); } bool flag4 = this.pageBreakCols == null; if (flag4) { this.pageBreakCols = new List(); } else { this.pageBreakCols.Clear(); } this.CheckAndInitPrintableRegion(); Rect rangePhysicsBounds = this.GetRangePhysicsBounds(this.printableRange); this.pageBreakRows.Add(this.printableRange.Row); this.pageBreakCols.Add(this.printableRange.Col); int num = this.printableRange.EndRow + 1; int num2 = this.printableRange.EndCol + 1; float num3 = (this.printSettings == null) ? 1f : this.printSettings.PageScaling; Rect paperPrintBounds = this.GetPaperPrintBounds(); float num4 = paperPrintBounds.Width / num3; float num5 = paperPrintBounds.Height / num3; double x = (double)(rangePhysicsBounds.Left + num4); double y = (double)(rangePhysicsBounds.Top + num5); int row = this.PrintableRange.Row; int col = this.PrintableRange.Col; Func callFunc = null; while (y < (double)rangePhysicsBounds.Bottom || row < num) { int num6 = ArrayHelper.QuickFind(row + 1, num, delegate(int i) { RowHeader rowHeader = this.rows[i]; bool flag12 = (double)rowHeader.Bottom < y; int result; if (flag12) { result = 1; } else { bool flag13 = (double)rowHeader.Top > y; if (flag13) { result = -1; } else { result = 0; } } return result; }); bool flag5 = this.userPageBreakRows != null && this.userPageBreakRows.Count > 0; if (flag5) { IEnumerable source = this.userPageBreakRows; Func predicate; if ((predicate = callFunc) == null) { predicate = (callFunc = ((int ur) => ur > row)); } int num7 = source.FirstOrDefault(predicate); bool flag6 = num7 != 0 && num7 < num6; if (flag6) { num6 = num7; } } bool flag7 = num6 >= num; if (flag7) { this.pageBreakRows.Add(num6); break; } this.pageBreakRows.Add(num6); row = num6; y = (double)((float)this.rows[num6].Top + num5); } Func callFunc2 = null; while (x < (double)rangePhysicsBounds.Right || col < num2) { int num8 = ArrayHelper.QuickFind(col + 1, num2, delegate(int i) { ColumnHeader columnHeader = this.cols[i]; bool flag12 = (double)columnHeader.Right < x; int result; if (flag12) { result = 1; } else { bool flag13 = (double)columnHeader.Left > x; if (flag13) { result = -1; } else { result = 0; } } return result; }); bool flag8 = this.userPageBreakCols != null && this.userPageBreakCols.Count > 0; if (flag8) { IEnumerable source2 = this.userPageBreakCols; Func predicate2; if ((predicate2 = callFunc2) == null) { predicate2 = (callFunc2 = ((int uc) => uc > col)); } int num9 = source2.FirstOrDefault(predicate2); bool flag9 = num9 != 0 && num9 < num8; if (flag9) { num8 = num9; } } bool flag10 = num8 >= num2; if (flag10) { this.pageBreakCols.Add(num8); break; } this.pageBreakCols.Add(num8); col = num8; x = (double)((float)this.cols[num8].Left + num4); } this.RequestInvalidate(); stopwatch.Stop(); long elapsedMilliseconds = stopwatch.ElapsedMilliseconds; this._Debug_Validate_PrintPageBreaks(); bool flag11 = elapsedMilliseconds > 10L; if (flag11) { Debug.WriteLine("Auto split page takes " + elapsedMilliseconds.ToString() + " ms."); } } internal void CheckAndInitPrintableRegion() { bool flag = false; bool flag2 = false; bool isEmpty = this.printableRange.IsEmpty; if (isEmpty) { flag = true; flag2 = true; this.PrintableRange = new RangePosition(0, 0, this.MaxContentRow + 1, this.MaxContentCol + 1); } else { bool flag3 = this.userPageBreakCols == null || this.userPageBreakCols.Count < 2; if (flag3) { flag = true; } bool flag4 = this.userPageBreakRows == null || this.userPageBreakRows.Count < 2; if (flag4) { flag2 = true; } } bool flag5 = flag; if (flag5) { bool flag6 = this.userPageBreakCols == null; if (flag6) { this.userPageBreakCols = new List(); } else { this.userPageBreakCols.Clear(); } this.userPageBreakCols.Add(this.printableRange.Col); this.userPageBreakCols.Add(this.printableRange.EndCol + 1); } bool flag7 = flag2; if (flag7) { bool flag8 = this.userPageBreakRows == null; if (flag8) { this.userPageBreakRows = new List(); } else { this.userPageBreakRows.Clear(); } this.userPageBreakRows.Add(this.printableRange.Row); this.userPageBreakRows.Add(this.printableRange.EndRow + 1); } } internal void ClearUserPageBreaks() { bool flag = this.userPageBreakRows == null; if (flag) { this.userPageBreakRows = new List(); } else { this.userPageBreakRows.Clear(); } bool flag2 = this.userPageBreakCols == null; if (flag2) { this.userPageBreakCols = new List(); } else { this.userPageBreakCols.Clear(); } } internal int FindBreakIndexOfRowByPixel(Point p) { Debug.Assert(this.pageBreakCols != null); bool flag = this.pageBreakRows == null || this.pageBreakRows.Count <= 0 || this.pageBreakCols == null || this.pageBreakCols.Count <= 0; int result; if (flag) { result = -1; } else { float num = (float)this.cols[this.pageBreakCols[0]].Left; bool flag2 = p.X < num; if (flag2) { result = -1; } else { int num2 = this.pageBreakCols[this.pageBreakCols.Count - 1]; bool flag3 = num2 >= this.cols.Count; if (flag3) { num2 = this.cols.Count; } float num3 = (float)((num2 < this.cols.Count) ? this.cols[num2].Left : this.cols[num2 - 1].Right); bool flag4 = p.X > num3; if (flag4) { result = -1; } else { for (int i = 0; i < this.pageBreakRows.Count; i++) { bool flag5 = this.IsSplitRowHoverByMouse(i, p.Y); if (flag5) { return i; } } result = -1; } } } return result; } internal int FindBreakIndexOfColumnByPixel(Point p) { Debug.Assert(this.pageBreakRows != null); Debug.Assert(this.pageBreakCols != null); bool flag = this.pageBreakRows == null || this.pageBreakRows.Count <= 0 || this.pageBreakCols == null || this.pageBreakCols.Count <= 0; int result; if (flag) { result = -1; } else { float num = (float)this.rows[this.pageBreakRows[0]].Top; bool flag2 = p.Y < num; if (flag2) { result = -1; } else { int num2 = this.pageBreakRows[this.pageBreakRows.Count - 1]; bool flag3 = num2 >= this.rows.Count; if (flag3) { num2 = this.rows.Count - 1; } float num3 = (float)((num2 < this.rows.Count) ? this.rows[num2].Bottom : this.rows[num2 - 1].Bottom); bool flag4 = p.Y > num3; if (flag4) { result = -1; } else { for (int i = 0; i < this.pageBreakCols.Count; i++) { bool flag5 = this.IsSplitColHoverByMouse(i, p.X); if (flag5) { return i; } } result = -1; } } } return result; } internal bool IsSplitRowHoverByMouse(int breakIndex, float y) { int num = this.pageBreakRows[breakIndex]; bool flag = num < this.rows.Count; int num2; if (flag) { RowHeader rowHeader = this.rows[num]; num2 = rowHeader.Top; } else { RowHeader rowHeader2 = this.rows[num - 1]; num2 = rowHeader2.Bottom; } float num3 = 2f / this.renderScaleFactor; return (float)num2 - num3 <= y && (float)num2 + num3 > y; } internal bool IsSplitColHoverByMouse(int breakIndex, float x) { int num = this.pageBreakCols[breakIndex]; bool flag = num < this.cols.Count; int num2; if (flag) { ColumnHeader columnHeader = this.cols[num]; num2 = columnHeader.Left; } else { ColumnHeader columnHeader2 = this.cols[num - 1]; num2 = columnHeader2.Right; } float num3 = 2f / this.renderScaleFactor; return (float)num2 - num3 <= x && (float)num2 + num3 > x; } public void AutoSetMaximumScaleForPages() { bool flag = this.printSettings == null; if (flag) { this.printSettings = new PrintSettings(); } Rect paperBounds = this.GetPaperPrintBounds(); float minScale = 1f; this.IteratePrintPages(this.printSettings.PageOrder, delegate(RangePosition range) { Size size = this.GetRangePhysicsBounds(range).Size; float num = paperBounds.Width / size.Width; float num2 = paperBounds.Height / size.Height; bool flag2 = minScale > num; if (flag2) { minScale = num; } bool flag3 = minScale > num2; if (flag3) { minScale = num2; } return true; }); this.printSettings.PageScaling = minScale; this._Debug_Validate_PrintPageBreaks(); Debug.WriteLine("Print scale set to " + this.printSettings.PageScaling.ToString() + "f."); } public PrintSession CreatePrintSession() { bool flag = this.pageBreakRows == null || this.pageBreakCols == null || this.pageBreakRows.Count == 0 || this.pageBreakCols.Count == 0; if (flag) { this.AutoSplitPage(); } bool flag2 = this.pageBreakRows == null || this.pageBreakRows == null || this.pageBreakRows.Count == 0 || this.pageBreakRows.Count == 0; if (flag2) { throw new NoPrintableContentException(); } bool flag3 = this.printSettings == null; if (flag3) { this.printSettings = new PrintSettings(); } PrintSession printSession = new PrintSession(); printSession.worksheets.Add(this); printSession.Init(); return printSession; } internal Rect GetPaperPrintBounds() { float num = 100f; float num2 = 100f; Size paperSizeInPixel = this.GetPaperSizeInPixel(num, num2); float num3 = MeasureToolkit.InchToPixel(this.printSettings.Margins.Left, num); float num4 = MeasureToolkit.InchToPixel(this.printSettings.Margins.Right, num); float num5 = MeasureToolkit.InchToPixel(this.printSettings.Margins.Top, num2); float num6 = MeasureToolkit.InchToPixel(this.printSettings.Margins.Bottom, num2); float num7 = (float)((int)Math.Floor((double)num3)); float num8 = (float)((int)Math.Floor((double)num5)); float num9 = (float)((int)Math.Ceiling((double)(paperSizeInPixel.Width - num3 - num4))); float num10 = (float)((int)Math.Ceiling((double)(paperSizeInPixel.Height - num5 - num6))); return new Rect(ref num7, ref num8, ref num9, ref num10); } internal Size GetPaperSizeInPixel(float dpix, float dpiy) { bool flag = this.printSettings == null; if (flag) { this.printSettings = new PrintSettings(); } float paperWidth = this.printSettings.PaperWidth; float paperHeight = this.printSettings.PaperHeight; int num = (int)Math.Ceiling((double)MeasureToolkit.InchToPixel(paperWidth, dpix)); int num2 = (int)Math.Ceiling((double)MeasureToolkit.InchToPixel(paperHeight, dpiy)); Size result; if (!this.printSettings.Landscape) { float num3 = (float)num; float num4 = (float)num2; result = new Size(ref num3, ref num4); } else { float num5 = (float)num2; float num6 = (float)num; result = new Size(ref num5, ref num6); } return result; } public void IteratePrintPages(Func iterator) { this.IteratePrintPages(PrintPageOrder.DownThenOver, iterator); } public void IteratePrintPages(PrintPageOrder pageOrder, Func iterator) { int num = 0; int num2 = 0; for (;;) { int num3 = this.pageBreakRows[num]; int num4 = this.pageBreakCols[num2]; int num5 = this.pageBreakRows[num + 1] - 1; int num6 = this.pageBreakCols[num2 + 1] - 1; bool flag = !iterator(new RangePosition(num3, num4, num5 - num3 + 1, num6 - num4 + 1)); if (flag) { break; } bool flag2 = pageOrder == PrintPageOrder.DownThenOver; if (flag2) { bool flag3 = num < this.pageBreakRows.Count - 2; if (flag3) { num++; } else { bool flag4 = num2 < this.pageBreakCols.Count - 2; if (!flag4) { break; } num = 0; num2++; } } else { bool flag5 = pageOrder == PrintPageOrder.OverThenDown; if (!flag5) { break; } bool flag6 = num2 < this.pageBreakCols.Count - 2; if (flag6) { num2++; } else { bool flag7 = num < this.pageBreakRows.Count - 2; if (!flag7) { break; } num2 = 0; num++; } } } } public void ChangeColumnPageBreak(int oldIndex, int newIndex, bool refreshPageBreaks = true) { bool flag = this.pageBreakCols == null || this.pageBreakCols.Count < 2; if (flag) { throw new InvalidOperationException("No page breaks exist. Try call AutoSplitPage method firstly."); } bool flag2 = this.pageBreakCols.IndexOf(oldIndex) < 0 && (this.userPageBreakCols == null || this.userPageBreakCols.IndexOf(oldIndex) < 0); if (flag2) { throw new PageBreakNotFoundException(oldIndex); } bool flag3 = newIndex < 0 || newIndex > this.cols.Count; if (flag3) { throw new IndexOutOfRangeException("Specified index out of the available range on spreadsheet"); } bool flag4 = (oldIndex != this.printableRange.Col && newIndex < this.printableRange.Col) || (oldIndex != this.printableRange.EndCol + 1 && newIndex > this.printableRange.EndCol + 1); if (flag4) { throw new ArgumentException("Cannot move to the new position that is out of the printable range. Change PrintableRange property firstly.", "newIndex"); } this.pageBreakCols.RemoveAll((int bc) => bc >= oldIndex && bc <= newIndex); this.pageBreakCols.Add(newIndex); this.pageBreakCols.Sort(); bool flag5 = oldIndex == this.userPageBreakCols.First(); bool flag6 = oldIndex == this.userPageBreakRows.Last(); this.userPageBreakCols.RemoveAll((int uc) => uc == oldIndex || uc == newIndex); this.userPageBreakCols.Add(newIndex); this.userPageBreakCols.Sort(); bool flag7 = this.userPageBreakCols.Last() == newIndex; if (flag7) { this.printableRange.EndCol = newIndex - 1; } else { bool flag8 = this.userPageBreakCols.First() == newIndex; if (flag8) { this.printableRange.Cols = this.printableRange.Cols - (newIndex - this.printableRange.Col); this.printableRange.Col = newIndex; Debug.Assert(this.printableRange.Col >= 0); Debug.Assert(this.printableRange.EndCol <= this.cols.Count - 1); } } bool flag9 = !flag5 && !flag6; if (flag9) { this.AutoSetMaximumScaleForPages(); } if (refreshPageBreaks) { this.AutoSplitPage(); } } public void ChangeRowPageBreak(int oldIndex, int newIndex, bool refreshPageBreaks = true) { bool flag = this.pageBreakRows == null || this.pageBreakRows.Count < 2; if (flag) { throw new InvalidOperationException("No page breaks exist. Try call AutoSplitPage method firstly."); } bool flag2 = this.pageBreakRows.IndexOf(oldIndex) < 0 && (this.userPageBreakRows == null || this.userPageBreakRows.IndexOf(oldIndex) < 0); if (flag2) { throw new PageBreakNotFoundException(oldIndex); } bool flag3 = newIndex < 0 || newIndex > this.rows.Count; if (flag3) { throw new IndexOutOfRangeException("Specified index out of the available range on worksheet"); } bool flag4 = (oldIndex != this.printableRange.Row && newIndex < this.printableRange.Row) || (oldIndex != this.printableRange.EndRow + 1 && newIndex > this.printableRange.EndRow + 1); if (flag4) { throw new ArgumentException("Cannot move to the new position that is out of the printable range. Change PrintableRange property firstly.", "newIndex"); } this.pageBreakRows.RemoveAll((int br) => br >= oldIndex && br <= newIndex); this.pageBreakRows.Add(newIndex); this.pageBreakRows.Sort(); bool flag5 = oldIndex == this.userPageBreakCols.First(); bool flag6 = oldIndex == this.userPageBreakRows.Last(); this.userPageBreakRows.RemoveAll((int uc) => uc == oldIndex || uc == newIndex); this.userPageBreakRows.Add(newIndex); this.userPageBreakRows.Sort(); bool flag7 = this.userPageBreakRows.Last() == newIndex; if (flag7) { this.printableRange.EndRow = newIndex - 1; } else { bool flag8 = this.userPageBreakRows.First() == newIndex; if (flag8) { this.printableRange.Rows = this.printableRange.Rows - (newIndex - this.printableRange.Row); this.printableRange.Row = newIndex; Debug.Assert(this.printableRange.Row >= 0); Debug.Assert(this.printableRange.Rows <= this.rows.Count - 1); } } bool flag9 = !flag5 && !flag6; if (flag9) { this.AutoSetMaximumScaleForPages(); } if (refreshPageBreaks) { this.AutoSplitPage(); } } public void InsertColumnPageBreak(int columnIndex, bool refreshPageBreaks = true) { bool flag = this.userPageBreakCols == null || this.userPageBreakCols.Count < 2; if (flag) { this.CheckAndInitPrintableRegion(); } bool flag2 = !this.userPageBreakCols.Contains(columnIndex); if (flag2) { this.userPageBreakCols.Add(columnIndex); this.userPageBreakCols.Sort(); bool flag3 = this.printableRange.EndCol < columnIndex - 1; if (flag3) { this.printableRange.EndCol = columnIndex - 1; } if (refreshPageBreaks) { this.AutoSplitPage(); } } } public void InsertRowPageBreak(int rowIndex, bool refreshPageBreaks = true) { bool flag = this.userPageBreakRows == null || this.userPageBreakRows.Count < 2; if (flag) { this.CheckAndInitPrintableRegion(); } bool flag2 = !this.userPageBreakRows.Contains(rowIndex); if (flag2) { this.userPageBreakRows.Add(rowIndex); this.userPageBreakRows.Sort(); bool flag3 = this.printableRange.EndRow < rowIndex - 1; if (flag3) { this.printableRange.EndRow = rowIndex - 1; } if (refreshPageBreaks) { this.AutoSplitPage(); } } } public void RemoveColumnPageBreak(int columnIndex) { bool flag = (this.pageBreakCols == null || !this.pageBreakCols.Contains(columnIndex)) && (this.userPageBreakCols == null || !this.userPageBreakCols.Contains(columnIndex)); if (flag) { throw new PageBreakNotFoundException(columnIndex); } bool flag2 = this.userPageBreakCols == null || this.userPageBreakCols.Count <= 2; if (flag2) { throw new PageBreakCannotRemoveException(columnIndex); } this.pageBreakCols.RemoveAll((int br) => br == columnIndex); this.pageBreakCols.Sort(); this.userPageBreakCols.RemoveAll((int uc) => uc == columnIndex || uc == columnIndex); this.AutoSetMaximumScaleForPages(); this.AutoSplitPage(); } public void RemoveRowPageBreak(int rowIndex) { bool flag = (this.pageBreakRows == null || !this.pageBreakRows.Contains(rowIndex)) && (this.userPageBreakRows == null || !this.userPageBreakRows.Contains(rowIndex)); if (flag) { throw new PageBreakNotFoundException(rowIndex); } bool flag2 = this.userPageBreakRows == null || this.userPageBreakRows.Count <= 2; if (flag2) { throw new PageBreakCannotRemoveException(rowIndex); } this.pageBreakRows.RemoveAll((int br) => br == rowIndex); this.pageBreakRows.Sort(); this.userPageBreakRows.RemoveAll((int uc) => uc == rowIndex || uc == rowIndex); this.AutoSetMaximumScaleForPages(); this.AutoSplitPage(); } public void ClearColumnPageBreaks() { bool flag = this.userPageBreakCols != null && this.userPageBreakCols.Count > 2; if (flag) { while (this.userPageBreakCols.Count > 2) { this.userPageBreakCols.RemoveAt(1); } this.userPageBreakCols.Sort(); this.AutoSplitPage(); } } public void ClearRowPageBreaks() { bool flag = this.userPageBreakRows != null && this.userPageBreakRows.Count > 2; if (flag) { while (this.userPageBreakRows.Count > 2) { this.userPageBreakRows.RemoveAt(1); } this.userPageBreakRows.Sort(); this.AutoSplitPage(); } } public void ClearAllPageBreaks() { bool flag = this.userPageBreakCols != null; if (flag) { this.userPageBreakCols.Clear(); } bool flag2 = this.userPageBreakRows != null; if (flag2) { this.userPageBreakRows.Clear(); } bool flag3 = this.MaxContentRow > 0 && this.MaxContentCol > 0; if (flag3) { this.AutoSplitPage(); } } public int PrintPageCounts { get { return (this.pageBreakCols == null || this.pageBreakCols.Count == 0 || this.pageBreakRows == null || this.pageBreakRows.Count == 0) ? 0 : ((this.pageBreakCols.Count - 1) * (this.pageBreakRows.Count - 1)); } } private void RaisePrintableRangeChangedEvent() { bool flag = this.PrintableRangeChanged != null; if (flag) { this.PrintableRangeChanged(this, null); } } internal int FixPageBreakColIndex(int index, int col) { bool flag = index == 0; if (flag) { int num = this.printableRange.IsEmpty ? this.rows.Count : this.printableRange.EndCol; bool flag2 = col >= num; if (flag2) { col = num; } } else { bool flag3 = index == this.pageBreakCols.Count - 1; if (flag3) { int num2 = this.printableRange.IsEmpty ? 0 : this.printableRange.Col; bool flag4 = col <= num2; if (flag4) { col = num2 + 1; } } else { int endCol = this.printableRange.EndCol; bool flag5 = col > endCol + 1; if (flag5) { col = endCol + 1; } else { int col2 = this.printableRange.Col; bool flag6 = col < col2; if (flag6) { col = col2; } } } } return col; } internal int FixPageBreakRowIndex(int index, int row) { bool flag = index == 0; if (flag) { int num = this.printableRange.IsEmpty ? this.rows.Count : this.printableRange.EndRow; bool flag2 = row >= num; if (flag2) { row = num; } } else { bool flag3 = index == this.pageBreakRows.Count - 1; if (flag3) { int num2 = this.printableRange.IsEmpty ? 0 : this.printableRange.Row; bool flag4 = row <= num2; if (flag4) { row = num2 + 1; } } else { int endRow = this.printableRange.EndRow; bool flag5 = row > endRow + 1; if (flag5) { row = endRow + 1; } else { int row2 = this.printableRange.Row; bool flag6 = row < row2; if (flag6) { row = row2; } } } } return row; } public void _Debug_Validate_PrintPageBreaks() { bool flag = this.printSettings == null; if (flag) { throw new Exception("print settings is null"); } bool isEmpty = this.printableRange.IsEmpty; if (isEmpty) { throw new Exception("no printable range initialized"); } bool flag2 = this.userPageBreakCols == null || this.userPageBreakCols.Count < 2; if (flag2) { throw new Exception("user column page breaks invalid"); } bool flag3 = this.userPageBreakRows == null || this.userPageBreakRows.Count < 2; if (flag3) { throw new Exception("user row page breaks invalid"); } bool flag4 = this.userPageBreakCols[0] != this.printableRange.Col; if (flag4) { throw new Exception("user col left != printable range"); } bool flag5 = this.userPageBreakCols.Last() != this.printableRange.EndCol + 1; if (flag5) { throw new Exception("user col right != printable range"); } bool flag6 = this.userPageBreakRows[0] != this.printableRange.Row; if (flag6) { throw new Exception("user row left != printable range"); } bool flag7 = this.userPageBreakRows.Last() != this.printableRange.EndRow + 1; if (flag7) { throw new Exception("user row right != printable range"); } foreach (int item in this.userPageBreakCols) { bool flag8 = !this.pageBreakCols.Contains(item); if (flag8) { throw new Exception("col user page break not containing in page breaks"); } } foreach (int item2 in this.userPageBreakRows) { bool flag9 = !this.pageBreakRows.Contains(item2); if (flag9) { throw new Exception("row user page break not containing in page breaks"); } } Func, bool> func = delegate(List a) { List list = new List(a.Distinct()); list.Sort(); bool flag16 = a.Count != list.Count; bool result; if (flag16) { result = false; } else { for (int i = 0; i < a.Count; i++) { bool flag17 = a[i] != list[i]; if (flag17) { return false; } } result = true; } return result; }; bool flag10 = !func(this.pageBreakCols); if (flag10) { throw new Exception("col page break contains invalid index"); } bool flag11 = !func(this.pageBreakRows); if (flag11) { throw new Exception("row page break contains invalid index"); } bool flag12 = !func(this.userPageBreakCols); if (flag12) { throw new Exception("user col page break contains invalid index"); } bool flag13 = !func(this.userPageBreakRows); if (flag13) { throw new Exception("user row page break contains invalid index"); } bool flag14 = this.printSettings != null && this.printSettings.PageScaling < 0f; if (flag14) { throw new Exception("page scale < 0"); } Rect paperPrintBounds = this.GetPaperPrintBounds(); float width = paperPrintBounds.Width; float height = paperPrintBounds.Height; float num = (this.printSettings == null) ? 1f : this.printSettings.PageScaling; int num2 = (this.pageBreakRows.Count - 1) * (this.pageBreakCols.Count - 1); int printPageCounts = this.PrintPageCounts; bool flag15 = num2 != printPageCounts; if (flag15) { throw new Exception(string.Format("page count incorrect, expect {0} but {1}", printPageCounts, num2)); } } public Worksheet.ReoGridRangeCollection Ranges { get { bool flag = this.rangeCollection == null; if (flag) { this.rangeCollection = new Worksheet.ReoGridRangeCollection(this); } return this.rangeCollection; } } public object[,] GetRangeData(RangePosition range) { RangePosition rangePosition = this.FixRange(range); object[,] array = new object[rangePosition.Rows, rangePosition.Cols]; int i = rangePosition.Row; int num = 0; while (i <= rangePosition.EndRow) { int j = rangePosition.Col; int num2 = 0; while (j <= rangePosition.EndCol) { array[num, num2] = ((this.cells[i, j] == null) ? null : this.cells[i, j].InnerData); j++; num2++; } i++; num++; } return array; } public void DeleteRangeData(string addressOrName) { bool flag = RangePosition.IsValidAddress(addressOrName); if (flag) { this.DeleteRangeData(new RangePosition(addressOrName), true); } else { NamedRange refRange; bool flag2 = this.registeredNamedRanges.TryGetValue(addressOrName, out refRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } this.DeleteRangeData(refRange, true); } } public void DeleteRangeData(RangePosition range) { this.DeleteRangeData(range, false); } public void DeleteRangeData(RangePosition range, bool checkReadonly = false) { RangePosition range2 = this.FixRange(range); int maxcol = range.Col; List formulaDirtyCells = new List(); this.IterateCells(range2, delegate(int row, int col, Cell cell) { bool flag2 = maxcol < col; if (flag2) { maxcol = col; } bool flag3 = !checkReadonly || !cell.IsReadOnly; if (flag3) { cell.InnerData = null; cell.InnerDisplay = string.Empty; cell.TextBounds = default(Rect); cell.RenderColor = Color.Transparent; cell.RenderScaleFactor = this.renderScaleFactor; cell.InnerFormula = null; cell.FormulaTree = null; this.ClearCellReferenceList(cell); bool flag4 = formulaDirtyCells.Contains(cell); if (flag4) { formulaDirtyCells.Remove(cell); } cell.FontDirty = false; } Func callFunc = null; foreach (KeyValuePair> keyValuePair in this.formulaRanges) { IEnumerable value = keyValuePair.Value; Func predicate; if ((predicate = callFunc) == null) { predicate = (callFunc = ((ReferenceRange r) => r.Contains(cell.InternalPos))); } bool flag5 = value.Any(predicate) && !formulaDirtyCells.Contains(keyValuePair.Key); if (flag5) { formulaDirtyCells.Add(keyValuePair.Key); } } return true; }); foreach (Cell cell2 in formulaDirtyCells) { this.RecalcCell(cell2, null); } for (int i = range2.Col; i <= maxcol; i++) { ColumnHeader columnHeader = this.cols[i]; bool flag = columnHeader.Body != null; if (flag) { columnHeader.Body.OnDataChange(range2.Row, range2.EndRow); } } this.RaiseRangeDataChangedEvent(range2); this.RequestInvalidate(); } public void SetRangeData(string addressOrName, object data) { bool flag = RangePosition.IsValidAddress(addressOrName); if (flag) { this.SetRangeData(new RangePosition(addressOrName), data); } else { NamedRange refRange; bool flag2 = this.registeredNamedRanges.TryGetValue(addressOrName, out refRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } this.SetRangeData(refRange, data); } } public void SetRangeData(int row, int col, int rows, int cols, object data) { this.SetRangeData(new RangePosition(row, col, rows, cols), data); } public void SetRangeData(RangePosition range, object data) { this.SetRangeData(range, data, false); } public void SetRangeData(RangePosition range, object data, bool checkReadonly) { bool isEmpty = range.IsEmpty; if (!isEmpty) { range = this.FixRange(range); bool flag = data is Array; if (flag) { Array array = (Array)data; bool flag2 = array.Rank == 2; if (flag2) { int length = array.GetLength(0); int length2 = array.GetLength(1); int num = Math.Max(length, range.Rows); int num2 = Math.Max(length2, range.Cols); int num3 = 0; while (num3 < num && num3 < length) { int num4 = 0; int num5 = 0; while (num4 < num2 && num5 < length2) { int num6 = range.Row + num3; int num7 = range.Col + num4; bool flag3 = num6 < this.rows.Count && num7 < this.cols.Count; if (flag3) { Cell cell = this.CreateAndGetCell(num6, num7); bool flag4 = !checkReadonly || !cell.IsReadOnly; if (flag4) { this.SetSingleCellData(cell, array.GetValue(num3, num5)); } num4 += (int)Math.Max((short)1, cell.Colspan); } num5++; } num3++; } } else { bool flag5 = array.Rank == 1; if (!flag5) { throw new ArgumentException("Array with more than 2 ranks is not supported."); } bool flag6 = array.Length > 0 && array.GetValue(0) is IEnumerable; bool flag7 = flag6; if (flag7) { int num8 = range.Row; int num9 = 0; while (num8 <= range.EndRow && num9 < array.Length) { int num10 = range.Col; IEnumerable enumerable = array.GetValue(num9) as IEnumerable; bool flag8 = enumerable != null; if (flag8) { foreach (object data2 in enumerable) { this.SetCellData(num8, num10, data2); num10++; bool flag9 = num10 > range.EndCol || num10 >= this.cols.Count; if (flag9) { break; } } } num8++; num9++; } } else { int num11 = range.Row; int num12 = range.Col; for (int i = 0; i < array.Length; i++) { object value = array.GetValue(i); this.SetCellData(num11, num12, value); num12++; bool flag10 = num12 > range.EndCol; if (flag10) { num11++; bool flag11 = num11 > range.EndRow; if (flag11) { break; } num12 = range.Col; } } } } } else { bool flag12 = data is IEnumerable; if (flag12) { IEnumerable enumerable2 = (IEnumerable)data; int num13 = range.Row; int num14 = range.Col; foreach (object data3 in enumerable2) { this.SetCellData(num13, num14, data3); bool flag13 = ++num13 > range.EndRow; if (flag13) { num13 = range.Row; bool flag14 = ++num14 > range.EndCol; if (flag14) { break; } } } } else { bool flag15 = data is DataTable; if (flag15) { this.SetRangeData(range, (DataTable)data); } else { bool flag16 = data is PartialGrid; if (flag16) { this.SetPartialGrid(range, (PartialGrid)data); } else { this.SetCellData(range.StartPos, data); } } } } } } public void SetRangeData(RangePosition range, DataTable table) { int num = range.Row; int num2 = 0; while (num <= range.EndRow && num2 < table.Rows.Count) { int num3 = range.Col; int num4 = 0; while (num3 <= range.EndCol && num4 < table.Columns.Count) { this.SetCellData(num, num3, table.Rows[num2][num4]); num3++; num4++; } num++; num2++; } } internal void RaiseRangeDataChangedEvent(RangePosition range) { bool flag = !this.suspendDataChangedEvent; if (flag) { bool flag2 = this.RangeDataChanged != null; if (flag2) { this.RangeDataChanged(this, new RangeEventArgs(range)); } } } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler RangeDataChanged; public CellPosition FixPos(CellPosition pos) { bool flag = pos.Row < 0; if (flag) { pos.Row = 0; } bool flag2 = pos.Col < 0; if (flag2) { pos.Col = 0; } bool flag3 = pos.Row > this.rows.Count - 1; if (flag3) { pos.Row = this.rows.Count - 1; } bool flag4 = pos.Col > this.cols.Count - 1; if (flag4) { pos.Col = this.cols.Count - 1; } return pos; } public RangePosition FixRange(RangePosition range) { range.StartPos = this.FixPos(range.StartPos); bool flag = range.Rows == -1; if (flag) { range.EndRow = this.rows.Count; } bool flag2 = range.Cols == -1; if (flag2) { range.EndCol = this.cols.Count; } bool flag3 = range.EndRow > this.rows.Count - 1 || range.Rows == -1; if (flag3) { range.EndRow = this.rows.Count - 1; } bool flag4 = range.EndCol > this.cols.Count - 1 || range.Cols == -1; if (flag4) { range.EndCol = this.cols.Count - 1; } return range; } public bool CheckRangeReadonly(RangePosition range) { bool foundReadonlyCell = false; this.IterateCells(range, delegate(int r, int c, Cell cell) { bool isReadOnly = cell.IsReadOnly; bool result; if (isReadOnly) { foundReadonlyCell = true; result = false; } else { result = true; } return result; }); return foundReadonlyCell; } public void ScrollToCell(string address) { this.ScrollToCell(new CellPosition(address)); } public void ScrollToCell(CellPosition pos) { this.ScrollToRange(new RangePosition(pos), pos); } public void ScrollToCell(Cell cell) { bool flag = cell.Worksheet != this; if (flag) { throw new ReferenceObjectNotAssociatedException("Specified cell does not belong to this worksheet."); } this.ScrollToCell(cell.InternalPos); } public void ScrollToCell(int row, int col) { this.ScrollToRange(this.FixRange(new RangePosition(row, col, 1, 1))); } public void ScrollToRange(string addressOrName) { bool flag = RangePosition.IsValidAddress(addressOrName); if (flag) { this.ScrollToRange(new RangePosition(addressOrName)); } else { NamedRange refRange; bool flag2 = this.registeredNamedRanges.TryGetValue(addressOrName, out refRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } this.ScrollToRange(refRange); } } public void ScrollToRange(int row, int col, int rows, int cols) { this.ScrollToRange(new RangePosition(row, col, rows, cols)); } public void ScrollToRange(RangePosition range) { this.ScrollToRange(range, range.EndPos); } public void ScrollToRange(RangePosition range, CellPosition basePos) { IScrollableViewportController scrollableViewportController = this.viewportController as IScrollableViewportController; bool flag = scrollableViewportController != null; if (flag) { scrollableViewportController.ScrollToRange(this.FixRange(range), basePos); } } public void MoveRange(string fromRangeAddress, string toRangeAddress) { bool flag = RangePosition.IsValidAddress(fromRangeAddress); RangePosition fromRange; if (flag) { fromRange = new RangePosition(fromRangeAddress); } else { bool flag2 = this.TryGetNamedRangePosition(fromRangeAddress, out fromRange); if (!flag2) { throw new InvalidAddressException(fromRangeAddress); } } bool flag3 = RangePosition.IsValidAddress(toRangeAddress); RangePosition toRange; if (flag3) { toRange = new RangePosition(toRangeAddress); } else { bool flag4 = this.TryGetNamedRangePosition(toRangeAddress, out toRange); if (!flag4) { throw new InvalidAddressException(toRangeAddress); } } this.MoveRange(fromRange, toRange); } public void MoveRange(RangePosition fromRange, RangePosition toRange) { this.MoveRange(fromRange, toRange, PartialGridCopyFlag.All); } public void MoveRange(RangePosition fromRange, RangePosition toRange, PartialGridCopyFlag flags = PartialGridCopyFlag.All) { this.CopyRange(fromRange, toRange, flags, true); } public void CopyRange(string fromRangeAddress, string toRangeAddress) { bool flag = RangePosition.IsValidAddress(fromRangeAddress); RangePosition fromRange; if (flag) { fromRange = new RangePosition(fromRangeAddress); } else { bool flag2 = !this.TryGetNamedRangePosition(fromRangeAddress, out fromRange); if (flag2) { throw new InvalidAddressException(fromRangeAddress); } } bool flag3 = RangePosition.IsValidAddress(toRangeAddress); RangePosition toRange; if (flag3) { toRange = new RangePosition(toRangeAddress); } else { bool flag4 = !this.TryGetNamedRangePosition(toRangeAddress, out toRange); if (flag4) { throw new InvalidAddressException(toRangeAddress); } } this.CopyRange(fromRange, toRange); } public void CopyRange(RangePosition fromRange, RangePosition toRange) { this.CopyRange(fromRange, toRange, PartialGridCopyFlag.All); } public void CopyRange(RangePosition fromRange, RangePosition toRange, PartialGridCopyFlag flags = PartialGridCopyFlag.All) { this.CopyRange(fromRange, toRange, flags, false); } internal void CopyRange(RangePosition fromRange, RangePosition toRange, PartialGridCopyFlag flags = PartialGridCopyFlag.All, bool moveRange = false) { bool flag = this.HasSettings(WorksheetSettings.Edit_Readonly); if (flag) { throw new CellDataReadonlyException(fromRange.StartPos); } bool flag2 = fromRange == toRange; if (!flag2) { RangePosition r = this.CheckIntersectedMergingRange(fromRange); bool flag3 = r != RangePosition.Empty; if (flag3) { throw new RangeIntersectionException(fromRange); } r = this.CheckIntersectedMergingRange(toRange); bool flag4 = r != RangePosition.Empty; if (flag4) { throw new RangeIntersectionException(toRange); } bool flag5 = this.CheckRangeReadonly(fromRange); if (flag5) { throw new RangeContainsReadonlyCellsException(fromRange); } bool flag6 = this.CheckRangeReadonly(toRange); if (flag6) { throw new RangeContainsReadonlyCellsException(fromRange); } BeforeCopyOrMoveRangeEventArgs beforeCopyOrMoveRangeEventArgs = new BeforeCopyOrMoveRangeEventArgs(fromRange, toRange); if (moveRange) { EventHandler beforeRangeMove = this.BeforeRangeMove; if (beforeRangeMove != null) { beforeRangeMove(this, beforeCopyOrMoveRangeEventArgs); } } else { EventHandler beforeRangeCopy = this.BeforeRangeCopy; if (beforeRangeCopy != null) { beforeRangeCopy(this, beforeCopyOrMoveRangeEventArgs); } } bool isCancelled = beforeCopyOrMoveRangeEventArgs.IsCancelled; if (!isCancelled) { PartialGrid partialGrid = this.GetPartialGrid(fromRange); if (moveRange) { this.UnmergeRange(fromRange); this.ClearRangeContent(fromRange, CellElementFlag.All, true); } this.SetPartialGrid(toRange, partialGrid); if (moveRange) { EventHandler afterRangeMove = this.AfterRangeMove; if (afterRangeMove != null) { afterRangeMove(this, new CopyOrMoveRangeEventArgs(fromRange, toRange)); } } else { EventHandler afterRangeCopy = this.AfterRangeCopy; if (afterRangeCopy != null) { afterRangeCopy(this, new CopyOrMoveRangeEventArgs(fromRange, toRange)); } } } } } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler BeforeRangeMove; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler BeforeRangeCopy; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler AfterRangeMove; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler AfterRangeCopy; public void ClearRangeContent(string addressOrName, CellElementFlag flags) { bool flag = RangePosition.IsValidAddress(addressOrName); if (flag) { this.ClearRangeContent(new RangePosition(addressOrName), flags, true); } else { NamedRange namedRange; bool flag2 = this.TryGetNamedRange(addressOrName, out namedRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } this.ClearRangeContent(namedRange.Position, flags, true); } } public void ClearRangeContent(RangePosition range, CellElementFlag flags, bool checkReadonly = true) { RangePosition range2 = this.FixRange(range); bool flag = (flags & CellElementFlag.Data) == CellElementFlag.Data; bool flag2 = (flags & CellElementFlag.Formula) == CellElementFlag.Formula; bool flag3 = (flags & CellElementFlag.DataFormat) == CellElementFlag.DataFormat; bool flag4 = (flags & CellElementFlag.Body) == CellElementFlag.Body; bool flag5 = (flags & CellElementFlag.Style) == CellElementFlag.Style; int num = range.Col; List list = new List(); for (int i = range2.Row; i <= range2.EndRow; i++) { for (int j = range2.Col; j <= range2.EndCol; j++) { Cell cell = this.cells[i, j]; bool flag6 = cell != null; if (flag6) { bool flag7 = false; bool flag8 = !checkReadonly || !cell.IsReadOnly; if (flag8) { bool flag9 = flag; if (flag9) { cell.InnerData = null; cell.InnerDisplay = string.Empty; bool flag10 = cell.InnerStyle.HAlign == ReoGridHorAlign.General; if (flag10) { cell.RenderHorAlign = ReoGridRenderHorAlign.Left; } flag7 = true; } bool flag11 = flag2; if (flag11) { cell.InnerFormula = null; this.ClearCellReferenceList(cell); } bool flag12 = flag3; if (flag12) { cell.DataFormat = CellDataFormatFlag.General; cell.DataFormatArgs = null; flag7 = true; } bool flag13 = flag4; if (flag13) { cell.body = null; flag7 = true; } bool flag14 = flag7; if (flag14) { bool flag15 = num < j; if (flag15) { num = j; } Func callFunc = null; foreach (KeyValuePair> keyValuePair in this.formulaRanges) { IEnumerable value = keyValuePair.Value; Func predicate; if ((predicate = callFunc) == null) { predicate = (callFunc = ((ReferenceRange rr) => rr.Contains(cell.InternalPos))); } bool flag16 = value.Any(predicate) && !list.Contains(keyValuePair.Key); if (flag16) { list.Add(keyValuePair.Key); } } this.RaiseCellDataChangedEvent(cell); } } } } } bool flag17 = flag5; if (flag17) { this.RemoveRangeStyles(range2, PlainStyleFlag.All); } foreach (Cell cell2 in list) { this.RecalcCell(cell2, null); } for (int k = range2.Col; k <= num; k++) { ColumnHeader columnHeader = this.cols[k]; bool flag18 = columnHeader.Body != null; if (flag18) { columnHeader.Body.OnDataChange(range2.Row, range2.EndRow); } } bool flag19 = (flags & CellElementFlag.Border) == CellElementFlag.Border; if (flag19) { this.RemoveRangeBorders(range2, BorderPositions.All); } this.RequestInvalidate(); } public HighlightRange FocusHighlightRange { get { return this.focusHighlightRange; } set { this.focusHighlightRange = value; bool flag = this.focusHighlightRange != null; if (flag) { this.controlAdapter.StartTimer(); } } } public ICollection HighlightRanges { get { bool flag = this.highlightRangeCollection == null; if (flag) { this.highlightRangeCollection = new Worksheet.HighlightRangeCollection(this); } return this.highlightRangeCollection; } } internal Color GetNextAvailableHighlightRangeColor() { Color[] namedRangeHighlightColors = Worksheet.NamedRangeHighlightColors; this.rangeHighlightColorCounter = this.rangeHighlightColorCounter++; Color result = namedRangeHighlightColors[(int)this.rangeHighlightColorCounter]; bool flag = (int)this.rangeHighlightColorCounter >= Worksheet.NamedRangeHighlightColors.Length; if (flag) { this.rangeHighlightColorCounter = 0; } return result; } public void StartCreateHighlightRange() { this.operationStatus = OperationStatus.HighlightRangeCreate; } public HighlightRange CreateHighlightRange(string addressOrName) { return this.CreateHighlightRange(addressOrName, this.GetNextAvailableHighlightRangeColor()); } public HighlightRange CreateHighlightRange(string addressOrName, Color color) { bool flag = RangePosition.IsValidAddress(addressOrName); HighlightRange result; if (flag) { result = this.CreateHighlightRange(new RangePosition(addressOrName), color); } else { NamedRange namedRange; bool flag2 = this.registeredNamedRanges.TryGetValue(addressOrName, out namedRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } result = this.CreateHighlightRange(namedRange.Position, color); } return result; } public HighlightRange CreateHighlightRange(RangePosition range, Color color) { return new HighlightRange(this, range) { HighlightColor = color }; } public HighlightRange AddHighlightRange(string address) { bool flag = RangePosition.IsValidAddress(address); HighlightRange result; if (flag) { result = this.AddHighlightRange(new RangePosition(address)); } else { bool flag2 = RGUtility.IsValidName(address); if (flag2) { NamedRange refRange; bool flag3 = this.registeredNamedRanges.TryGetValue(address, out refRange); if (flag3) { return this.AddHighlightRange(refRange); } } result = null; } return result; } public HighlightRange AddHighlightRange(RangePosition range) { for (int i = 0; i < this.highlightRanges.Count; i++) { HighlightRange highlightRange = this.highlightRanges[i]; bool flag = highlightRange.StartPos == range.StartPos && highlightRange.EndPos == range.EndPos; if (flag) { this.highlightRanges.RemoveAt(i); } } HighlightRange highlightRange2 = new HighlightRange(this, range); this.AddHighlightRange(highlightRange2); return highlightRange2; } internal void AddHighlightRange(HighlightRange range) { this.highlightRanges.Add(range); this.RequestInvalidate(); } public bool RemoveHighlightRange(string address) { bool flag = RangePosition.IsValidAddress(address); bool result; if (flag) { result = this.RemoveHighlightRange(new RangePosition(address)); } else { bool flag2 = RGUtility.IsValidName(address); if (flag2) { NamedRange refRange; bool flag3 = this.registeredNamedRanges.TryGetValue(address, out refRange); if (flag3) { return this.RemoveHighlightRange(refRange); } } result = false; } return result; } public bool RemoveHighlightRange(RangePosition range) { bool flag = false; for (int i = 0; i < this.highlightRanges.Count; i++) { bool flag2 = this.highlightRanges[i].StartPos == range.StartPos && this.highlightRanges[i].EndPos == range.EndPos; if (flag2) { this.highlightRanges.RemoveAt(i); flag = true; } } bool flag3 = flag; if (flag3) { this.RequestInvalidate(); } return flag; } public void RemoveAllHighlightRanges() { bool flag = this.highlightRanges != null && this.highlightRanges.Count > 0; if (flag) { this.highlightRanges.Clear(); this.RequestInvalidate(); } } public bool HasHighlightRange(RangePosition range) { for (int i = 0; i < this.highlightRanges.Count; i++) { bool flag = this.highlightRanges[i].StartPos == range.StartPos && this.highlightRanges[i].EndPos == range.EndPos; if (flag) { this.highlightRanges.RemoveAt(i); return true; } } return false; } public void TimerRun() { bool flag = this.focusHighlightRange == null; if (flag) { this.controlAdapter.StopTimer(); } else { this.RequestInvalidate(); } } public void MergeRange(string addressOrName) { bool flag = RangePosition.IsValidAddress(addressOrName); if (flag) { this.MergeRange(new RangePosition(addressOrName)); } else { NamedRange refRange; bool flag2 = this.registeredNamedRanges.TryGetValue(addressOrName, out refRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } this.MergeRange(refRange); } } public void MergeRange(int row, int col, int rows, int cols) { this.MergeRange(new RangePosition(row, col, rows, cols)); } public void MergeRange(RangePosition range) { this.MergeRange(range, true, true); } internal void MergeRange(RangePosition range, bool checkIntersection = true, bool updateUIAndEvent = true) { bool isEmpty = range.IsEmpty; if (!isEmpty) { RangePosition range2 = this.FixRange(range); bool flag = range2.Cols <= 1 && range2.Rows <= 1; if (!flag) { if (checkIntersection) { RangePosition range3 = this.CheckIntersectedMergingRange(range2); bool flag2 = !range3.IsEmpty; if (flag2) { throw new RangeIntersectionException(range3); } } int row = range2.Row; int col = range2.Col; int endRow = range2.EndRow; int endCol = range2.EndCol; Cell cell = this.cells[row, col]; Cell cell2 = this.cells[endRow, endCol]; bool flag3 = cell == null; if (flag3) { cell = this.CreateCell(row, col, true); } bool flag4 = cell2 == null; if (flag4) { cell2 = this.CreateCell(endRow, endCol, true); } for (int i = row; i <= endRow; i++) { for (int j = col; j <= endCol; j++) { Cell cell3 = this.CreateAndGetCell(i, j); cell3.MergeStartPos = cell.InternalPos; cell3.MergeEndPos = cell2.InternalPos; cell3.Colspan = 0; cell3.Rowspan = 0; bool flag5 = cell3 != cell; if (flag5) { cell3.InnerData = (cell3.InnerDisplay = null); } bool flag6 = i == row; if (flag6) { bool flag7 = j > col; if (flag7) { this.CutBeforeVBorder(i, j); } } else { this.hBorders[i, j] = new ReoGridHBorder { Span = 0 }; } bool flag8 = j == col; if (flag8) { bool flag9 = i > row; if (flag9) { this.CutBeforeHBorder(i, j); } } else { this.vBorders[i, j] = new ReoGridVBorder { Span = 0 }; } } } cell.Rowspan = (short)range2.Rows; cell.Colspan = (short)range2.Cols; this.UpdateCellBounds(cell); bool flag10 = this.selectionRange.IntersectWith(range2); if (flag10) { this.selectionRange = this.CheckMergedRange(range2); } bool flag11 = range2.Contains(this.focusPos); if (flag11) { this.focusPos = range2.StartPos; } if (updateUIAndEvent) { this.RequestInvalidate(); bool flag12 = this.RangeMerged != null; if (flag12) { this.RangeMerged(this, new RangeEventArgs(range2)); } } } } } public void UnmergeRange(int row, int col, int rows, int cols) { this.UnmergeRange(new RangePosition(row, col, rows, cols)); } public void UnmergeRange(RangePosition range) { bool isEmpty = range.IsEmpty; if (!isEmpty) { range = this.FixRange(range); int row = range.Row; int col = range.Col; int num = range.Row + range.Rows - 1; int num2 = range.Col + range.Cols - 1; for (int i = row; i <= num; i++) { for (int j = col; j <= num2; j++) { Cell cell = this.CreateAndGetCell(i, j); bool flag = cell.Colspan > 1 || cell.Rowspan > 1; if (flag) { this.UnmergeCell(cell); j += (int)cell.Colspan; } } } this.RequestInvalidate(); } } private void UnmergeCell(Cell source) { int num = source.InternalRow + (int)source.Rowspan; int num2 = source.InternalCol + (int)source.Colspan; RangePosition range = new RangePosition(source.InternalRow, source.InternalCol, (int)source.Rowspan, (int)source.Colspan); for (int i = source.InternalRow; i < num; i++) { for (int j = source.InternalCol; j < num2; j++) { Cell cell = this.CreateAndGetCell(i, j); cell.MergeStartPos = CellPosition.Empty; cell.MergeEndPos = CellPosition.Empty; cell.Colspan = 1; cell.Rowspan = 1; this.UpdateCellBounds(cell); bool flag = i != source.InternalRow; if (flag) { this.hBorders[i, j] = null; } bool flag2 = j != source.InternalCol; if (flag2) { this.vBorders[i, j] = null; } bool flag3 = i != source.InternalRow || j != source.InternalCol; if (flag3) { cell.InnerStyle = source.InnerStyle; cell.StyleParentKind = StyleParentKind.Range; } } } bool flag4 = this.RangeUnmerged != null; if (flag4) { this.RangeUnmerged(this, new RangeEventArgs(range)); } } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler RangeMerged; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler RangeUnmerged; public RangePosition CheckIntersectedMergingRange(RangePosition range) { RangePosition intersectedRange = RangePosition.Empty; this.cells.Iterate(range.Row, range.Col, range.Rows, range.Cols, true, delegate(int r, int c, Cell cell) { bool flag = !cell.MergeStartPos.IsEmpty; int result; if (flag) { Cell cell2 = this.GetCell(cell.MergeStartPos); for (int i = cell2.InternalRow; i <= cell2.MergeEndPos.Row; i++) { for (int j = cell2.InternalCol; j <= cell2.MergeEndPos.Col; j++) { Cell cell3 = this.cells[i, j]; bool flag2 = cell3 != null && !range.Contains(cell3.InternalPos); if (flag2) { intersectedRange = new RangePosition(cell2.InternalPos, cell2.MergeEndPos); break; } } bool flag3 = !intersectedRange.IsEmpty; if (flag3) { break; } } result = (int)(intersectedRange.IsEmpty ? 0 : cell.Colspan); } else { result = (int)((cell.Colspan < 1) ? 1 : cell.Colspan); } return result; }); return intersectedRange; } public bool HasIntersectedMergingRange(RangePosition range) { return !this.CheckIntersectedMergingRange(range).IsEmpty; } public RangePosition CheckMergedRange(RangePosition range) { int num = range.Row; int num2 = range.Col; int num3 = range.EndRow; int num4 = range.EndCol; bool flag; do { flag = false; for (int i = num; i <= num3; i++) { Cell cell = this.cells[i, num2]; bool flag2 = cell != null && cell.MergeStartPos != CellPosition.Empty; if (flag2) { int row = cell.MergeStartPos.Row; bool flag3 = num > row; if (flag3) { num = row; flag = true; } int col = cell.MergeStartPos.Col; bool flag4 = num2 > col; if (flag4) { num2 = col; flag = true; } } } for (int j = num; j <= num3; j++) { Cell cell = this.cells[j, num4]; bool flag5 = cell != null && cell.MergeEndPos != CellPosition.Empty; if (flag5) { int row2 = cell.MergeEndPos.Row; bool flag6 = num3 < row2; if (flag6) { num3 = row2; flag = true; } int col2 = cell.MergeEndPos.Col; bool flag7 = num4 < col2; if (flag7) { num4 = col2; flag = true; } } } for (int k = num2; k <= num4; k++) { Cell cell = this.cells[num, k]; bool flag8 = cell != null && cell.MergeStartPos != CellPosition.Empty; if (flag8) { int row3 = cell.MergeStartPos.Row; bool flag9 = num > row3; if (flag9) { num = row3; flag = true; } int col3 = cell.MergeStartPos.Col; bool flag10 = num2 > col3; if (flag10) { num2 = col3; flag = true; } } } for (int l = num2; l <= num4; l++) { Cell cell = this.cells[num3, l]; bool flag11 = cell != null && cell.MergeEndPos != CellPosition.Empty; if (flag11) { int row4 = cell.MergeEndPos.Row; bool flag12 = num3 < row4; if (flag12) { num3 = row4; flag = true; } int col4 = cell.MergeEndPos.Col; bool flag13 = num4 < col4; if (flag13) { num4 = col4; flag = true; } } } } while (flag); return new RangePosition(num, num2, num3 - num + 1, num4 - num2 + 1); } private bool IsInsideSameMergedCell(int r1, int c1, int r2, int c2) { return Worksheet.IsInsideSameMergedCell(this.cells[r1, c1], this.cells[r2, c2]); } private static bool IsInsideSameMergedCell(Cell cell1, Cell cell2) { return cell1 != null && cell2 != null && !cell1.MergeStartPos.IsEmpty && CellPosition.Equals(cell1.MergeStartPos, cell2.MergeStartPos); } public bool RangeIsMergedCell(RangePosition range) { Cell cell = this.cells[range.Row, range.Col]; return (cell == null && range.Rows == 1 && range.Cols == 1) || (cell != null && (int)cell.Rowspan == range.Rows && (int)cell.Colspan == range.Cols); } public void AddNamedRange(NamedRange namedRange) { bool flag = namedRange == null; if (flag) { throw new ArgumentNullException("namedRange", "Specified range object cannot be null"); } bool flag2 = string.IsNullOrEmpty(namedRange.Name); if (flag2) { throw new ArgumentNullException("namedRange.Name", "Name of range object cannot be empty"); } bool flag3 = namedRange.Worksheet != null && namedRange.Worksheet != this; if (flag3) { throw new ArgumentException("Specified range is belong to another worksheet, remove from other worksheet firstly, or create a new range at same position."); } Func, bool> callFunc = null; bool flag4 = namedRange.Scope == NamedRangeScope.Workbook && this.workbook.worksheets.Any(delegate(Worksheet s) { IEnumerable> source = s.registeredNamedRanges; Func, bool> predicate; if ((predicate = callFunc) == null) { predicate = (callFunc = ((KeyValuePair p) => p.Value.Scope == NamedRangeScope.Workbook && p.Key.Equals(namedRange.Name, StringComparison.CurrentCultureIgnoreCase))); } return source.Any(predicate); }); if (flag4) { throw new NamedRangeAlreadyDefinedException(); } this.registeredNamedRanges[namedRange.Name] = namedRange; namedRange.Worksheet = this; bool flag5 = this.NamedRangeDefined != null; if (flag5) { this.NamedRangeDefined(this, new NamedRangeAddedEventArgs(namedRange)); } } public NamedRange DefineNamedRange(string name, string address) { return this.DefineNamedRange(name, address, NamedRangeScope.Workbook); } public NamedRange DefineNamedRange(string name, string address, NamedRangeScope scope) { bool flag = !RangePosition.IsValidAddress(address); if (flag) { throw new InvalidAddressException(address); } return this.DefineNamedRange(name, new RangePosition(address), scope); } public NamedRange DefineNamedRange(string name, int row, int col, int rows, int cols) { return this.DefineNamedRange(name, new RangePosition(row, col, rows, cols), NamedRangeScope.Workbook); } public NamedRange DefineNamedRange(string name, int row, int col, int rows, int cols, NamedRangeScope scope) { return this.DefineNamedRange(name, new RangePosition(row, col, rows, cols), scope); } public NamedRange DefineNamedRange(string name, RangePosition range, NamedRangeScope scope = NamedRangeScope.Workbook) { NamedRange namedRange = new NamedRange(this, name, this.FixRange(range)) { Scope = scope }; this.AddNamedRange(namedRange); return namedRange; } public NamedRange GetNamedRange(string name) { bool flag = this.registeredNamedRanges == null; NamedRange result; if (flag) { result = null; } else { NamedRange namedRange; this.registeredNamedRanges.TryGetValue(name, out namedRange); result = namedRange; } return result; } public bool TryGetNamedRange(string name, out NamedRange namedRange) { bool flag = !RGUtility.IsValidName(name); bool result; if (flag) { namedRange = null; result = false; } else { result = this.registeredNamedRanges.TryGetValue(name, out namedRange); } return result; } internal bool TryGetNamedRangePosition(string name, out RangePosition range) { bool flag = !RGUtility.IsValidName(name); bool result; if (flag) { range = RangePosition.Empty; result = false; } else { NamedRange namedRange; this.registeredNamedRanges.TryGetValue(name, out namedRange); range = namedRange.Position; result = true; } return result; } public bool TryGetRangeByAddressOrName(string addressOrName, out RangePosition range) { bool flag = RangePosition.IsValidAddress(addressOrName); bool result; if (flag) { range = new RangePosition(addressOrName); result = true; } else { bool flag2 = NamedRange.IsValidName(addressOrName); if (flag2) { NamedRange refRange; bool flag3 = this.registeredNamedRanges.TryGetValue(addressOrName, out refRange); if (flag3) { range = refRange; return true; } } range = RangePosition.Empty; result = false; } return result; } public IEnumerable GetAllNamedRanges() { return this.registeredNamedRanges.Keys; } public string GetNameByRange(string address) { return RangePosition.IsValidAddress(address) ? this.GetNameByRange(new RangePosition(address)) : null; } public string GetNameByRange(RangePosition range) { KeyValuePair keyValuePair = this.registeredNamedRanges.FirstOrDefault((KeyValuePair nr) => nr.Value.StartPos == range.StartPos && nr.Value.EndPos == range.EndPos); return (keyValuePair.Key == null) ? null : keyValuePair.Key; } public bool UndefineNamedRange(string name) { NamedRange namedRange; bool flag = this.registeredNamedRanges.TryGetValue(name, out namedRange); bool result; if (flag) { namedRange.Worksheet = null; this.registeredNamedRanges.Remove(name); bool flag2 = this.NamedRangeUndefined != null; if (flag2) { this.NamedRangeUndefined(this, new NamedRangeUndefinedEventArgs(namedRange, namedRange.Name)); } result = true; } else { result = false; } return result; } public bool RenameNamedRange(string oldName, string newName) { NamedRange namedRange; bool flag = this.registeredNamedRanges.TryGetValue(oldName, out namedRange); bool result; if (flag) { namedRange.internalName = newName; this.registeredNamedRanges.Remove(oldName); this.registeredNamedRanges[newName] = namedRange; result = true; } else { result = false; } return result; } private string GetAvailableRangeName() { int num = 0; string result; while (this.registeredNamedRanges.ContainsKey(result = "__unnamed_range" + ((num == 0) ? string.Empty : ("_" + num.ToString())))) { num++; } return result; } public NamedRangeCollection NamedRanges { get { bool flag = this.namedRangeCollection == null; if (flag) { this.namedRangeCollection = new NamedRangeCollection(this); } return this.namedRangeCollection; } } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler NamedRangeDefined; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler NamedRangeUndefined; public void SetRangeStyles(string addressOrName, WorksheetRangeStyle style) { bool flag = RangePosition.IsValidAddress(addressOrName); if (flag) { this.SetRangeStyles(new RangePosition(addressOrName), style); } else { NamedRange refRange; bool flag2 = this.registeredNamedRanges.TryGetValue(addressOrName, out refRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } this.SetRangeStyles(refRange, style); } } public void SetRangeStyles(int row, int col, int rows, int cols, WorksheetRangeStyle style) { this.SetRangeStyles(new RangePosition(row, col, rows, cols), style); } public void SetRangeStyles(RangePosition range, WorksheetRangeStyle style) { bool flag = this.currentEditingCell != null; if (flag) { this.EndEdit(EndEditReason.NormalFinish); } RangePosition range2 = this.FixRange(range); int row = range2.Row; int col = range2.Col; int num = range2.EndRow; int num2 = range2.EndCol; bool flag2 = range2.Rows == this.rows.Count; bool flag3 = range2.Cols == this.cols.Count; bool flag4 = flag3 && flag2; bool flag5 = !flag2 && !flag3; int maxContentRow = 0; bool flag6 = flag2 && num > (maxContentRow = this.MaxContentRow); if (flag6) { num = maxContentRow; } int maxContentCol = 0; bool flag7 = flag3 && num2 > (maxContentCol = this.MaxContentCol); if (flag7) { num2 = maxContentCol; } StyleParentKind styleParentKind = StyleParentKind.Own; bool flag8 = flag4; if (flag8) { StyleUtility.CopyStyle(style, this.RootStyle); for (int i = 0; i < this.rows.Count; i++) { RowHeader rowHeader = this.rows[i]; bool flag9 = rowHeader != null && rowHeader.InnerStyle != null; if (flag9) { StyleUtility.CopyStyle(style, rowHeader.InnerStyle); } } for (int j = 0; j < this.cols.Count; j++) { ColumnHeader columnHeader = this.cols[j]; bool flag10 = columnHeader != null; if (flag10) { columnHeader.InnerStyle = null; } } styleParentKind = StyleParentKind.Root; } else { bool flag11 = flag3; if (flag11) { for (int k = row; k <= num; k++) { RowHeader rowHeader2 = this.rows[k]; bool flag12 = rowHeader2.InnerStyle == null; if (flag12) { rowHeader2.InnerStyle = StyleUtility.CreateMergedStyle(style, this.RootStyle); } else { StyleUtility.CopyStyle(style, rowHeader2.InnerStyle); } } styleParentKind = StyleParentKind.Row; } else { bool flag13 = flag2; if (flag13) { for (int l = col; l <= num2; l++) { ColumnHeader columnHeader2 = this.cols[l]; bool flag14 = columnHeader2.InnerStyle == null; if (flag14) { columnHeader2.InnerStyle = StyleUtility.CreateMergedStyle(style, this.RootStyle); } else { StyleUtility.CopyStyle(style, columnHeader2.InnerStyle); } } styleParentKind = StyleParentKind.Col; } } } for (int m = row; m <= num; m++) { WorksheetRangeStyle worksheetRangeStyle = null; int n = col; while (n <= num2) { Cell cell = this.cells[m, n]; WorksheetRangeStyle worksheetRangeStyle2 = null; bool flag15 = cell != null; if (flag15) { bool flag16 = cell.IsValidCell && ((!flag3 && !flag2) || (row <= cell.InternalRow && num >= cell.MergeEndPos.Row && col <= cell.InternalCol && num2 >= cell.MergeEndPos.Col)); if (flag16) { bool flag17 = styleParentKind == StyleParentKind.Row; if (flag17) { bool flag18 = cell.StyleParentKind == StyleParentKind.Col; if (flag18) { this.SetCellStyle(cell, style, StyleParentKind.Own, null); } else { bool flag19 = worksheetRangeStyle == null; if (flag19) { worksheetRangeStyle = this.rows[m].InnerStyle; } this.SetCellStyle(cell, style, styleParentKind, worksheetRangeStyle); } } else { bool flag20 = styleParentKind == StyleParentKind.Col; if (flag20) { bool flag21 = worksheetRangeStyle2 == null; if (flag21) { worksheetRangeStyle2 = this.cols[n].InnerStyle; } this.SetCellStyle(cell, style, styleParentKind, worksheetRangeStyle2); } else { this.SetCellStyle(cell, style, styleParentKind, this.RootStyle); } } } } else { bool flag22 = flag5; if (flag22) { cell = this.CreateCell(m, n, false); this.SetCellStyle(cell, style, StyleParentKind.Own, null); } else { bool flag23 = flag4; if (!flag23) { bool flag24 = flag2; if (flag24) { bool flag25 = worksheetRangeStyle == null; if (flag25) { worksheetRangeStyle = this.rows[m].InnerStyle; } bool flag26 = worksheetRangeStyle != null; if (flag26) { this.SetCellStyle(this.CreateCell(m, n, false), style, StyleParentKind.Own, null); } } } } } IL_439: n++; continue; goto IL_439; } } bool flag27 = this.RangeStyleChanged != null; if (flag27) { this.RangeStyleChanged(this, new RangeEventArgs(range2)); } this.RequestInvalidate(); } internal void SetCellStyleOwn(Cell cell, WorksheetRangeStyle style) { this.SetCellStyle(cell, style, StyleParentKind.Own, null); } internal void SetCellStyleOwn(CellPosition pos, WorksheetRangeStyle style) { this.SetCellStyleOwn(pos.Row, pos.Col, style); } internal void SetCellStyleOwn(int row, int col, WorksheetRangeStyle style) { this.SetCellStyle(this.CreateAndGetCell(row, col), style, StyleParentKind.Own, null); } private void SetCellStyle(Cell cell, WorksheetRangeStyle style, StyleParentKind parentKind, WorksheetRangeStyle parentStyle = null) { bool flag = cell.Rowspan == 0 || cell.Colspan == 0; if (!flag) { bool flag2 = cell.StyleParentKind == StyleParentKind.Own || parentKind == StyleParentKind.Own; if (flag2) { bool flag3 = cell.StyleParentKind != StyleParentKind.Own; if (flag3) { cell.CreateOwnStyle(); } StyleUtility.CopyStyle(style, cell.InnerStyle); bool flag4 = (cell.InnerStyle.Flag & PlainStyleFlag.FillPattern) == PlainStyleFlag.FillPattern && cell.InnerStyle.FillPatternColor.ToArgb() == 0; if (flag4) { cell.InnerStyle.Flag &= (PlainStyleFlag)(-1572865L); } bool flag5 = (cell.InnerStyle.Flag & PlainStyleFlag.BackColor) == PlainStyleFlag.BackColor && cell.InnerStyle.BackColor.ToArgb() == 0; if (flag5) { cell.InnerStyle.Flag &= (PlainStyleFlag)(-129L); } } else { cell.InnerStyle = ((parentStyle != null) ? parentStyle : style); cell.StyleParentKind = parentKind; } StyleUtility.UpdateCellRenderAlign(this, cell); bool flag6 = !string.IsNullOrEmpty(cell.DisplayText); if (flag6) { bool flag7 = style.Flag.HasAny(PlainStyleFlag.FontAll); if (flag7) { this.UpdateCellFont(cell, UpdateFontReason.FontChanged); } else { bool flag8 = style.Flag.HasAny((PlainStyleFlag)23093248L); if (flag8) { this.UpdateCellTextBounds(cell); } else { bool flag9 = style.Flag.Has(PlainStyleFlag.TextColor); if (flag9) { this.UpdateCellFont(cell, UpdateFontReason.TextColorChanged); } } } } bool flag10 = style.Flag.Has(PlainStyleFlag.Padding); if (flag10) { cell.UpdateContentBounds(); } bool flag11 = cell.body != null && style.Flag.HasAny(PlainStyleFlag.AlignAll); if (flag11) { cell.body.OnBoundsChanged(); } } } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler RangeStyleChanged; public void RemoveRangeStyles(string addressOrName, PlainStyleFlag flags) { bool flag = RangePosition.IsValidAddress(addressOrName); if (flag) { this.RemoveRangeStyles(new RangePosition(addressOrName), flags); } else { NamedRange refRange; bool flag2 = this.registeredNamedRanges.TryGetValue(addressOrName, out refRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } this.RemoveRangeStyles(refRange, flags); } } public void RemoveRangeStyles(RangePosition range, PlainStyleFlag flags) { RangePosition rangePosition = this.FixRange(range); int row = rangePosition.Row; int col = rangePosition.Col; int endRow = rangePosition.EndRow; int endCol = rangePosition.EndCol; bool flag = rangePosition.Rows == this.rows.Count; bool flag2 = rangePosition.Cols == this.cols.Count; bool flag3 = flag2 && flag; bool flag4 = !flag && !flag2; bool flag5 = flag3; if (flag5) { this.RootStyle.Flag &= ~flags; for (int i = 0; i < this.rows.Count; i++) { WorksheetRangeStyle innerStyle = this.rows[i].InnerStyle; bool flag6 = innerStyle != null; if (flag6) { innerStyle.Flag &= ~flags; } } for (int j = 0; j < this.cols.Count; j++) { WorksheetRangeStyle innerStyle2 = this.cols[j].InnerStyle; bool flag7 = innerStyle2 != null; if (flag7) { innerStyle2.Flag &= ~flags; } } } else { bool flag8 = flag2; if (flag8) { for (int k = row; k <= endRow; k++) { WorksheetRangeStyle innerStyle3 = this.rows[k].InnerStyle; bool flag9 = innerStyle3 != null; if (flag9) { innerStyle3.Flag &= ~flags; } } } else { bool flag10 = flag; if (flag10) { for (int l = col; l <= endCol; l++) { WorksheetRangeStyle innerStyle4 = this.cols[l].InnerStyle; bool flag11 = innerStyle4 != null; if (flag11) { innerStyle4.Flag &= ~flags; } } } } } for (int m = row; m <= endRow; m++) { int n = col; while (n <= endCol) { Cell cell = this.cells[m, n]; bool flag12 = cell == null; if (flag12) { n++; } else { bool flag13 = cell.Rowspan == 1 && cell.Colspan == 1; if (flag13) { this.RemoveCellStyle(cell, flags); n++; } else { bool flag14 = cell.IsStartMergedCell && row <= cell.MergeStartPos.Row && endRow >= cell.MergeEndPos.Row && col <= cell.MergeStartPos.Col && endCol >= cell.MergeEndPos.Col; if (flag14) { this.RemoveCellStyle(cell, flags); n += (int)cell.Colspan; } else { bool flag15 = !cell.MergeStartPos.IsEmpty; if (flag15) { n = cell.MergeEndPos.Col + 1; } } } } } } this.RequestInvalidate(); } private void RemoveCellStyle(Cell cell, PlainStyleFlag flags) { StyleParentKind styleParentKind = cell.StyleParentKind; bool flag = styleParentKind == StyleParentKind.Root; if (flag) { PlainStyleFlag plainStyleFlag = StyleUtility.CheckDistinctStyle(this.RootStyle, Worksheet.DefaultStyle); bool flag2 = plainStyleFlag == PlainStyleFlag.None; if (flag2) { return; } } RowHeader rowHeader = this.rows[cell.Row]; ColumnHeader columnHeader = this.cols[cell.Column]; bool flag3 = rowHeader.InnerStyle != null; WorksheetRangeStyle worksheetRangeStyle; StyleParentKind styleParentKind2; if (flag3) { worksheetRangeStyle = rowHeader.InnerStyle; styleParentKind2 = StyleParentKind.Row; } else { bool flag4 = columnHeader.InnerStyle != null; if (flag4) { worksheetRangeStyle = columnHeader.InnerStyle; styleParentKind2 = StyleParentKind.Col; } else { worksheetRangeStyle = this.RootStyle; styleParentKind2 = StyleParentKind.Root; } } bool flag5 = styleParentKind != StyleParentKind.Own; if (flag5) { cell.InnerStyle = new WorksheetRangeStyle(worksheetRangeStyle); cell.InnerStyle.Flag &= ~flags; } else { cell.InnerStyle.Flag &= ~flags; bool flag6 = cell.InnerStyle.Flag == PlainStyleFlag.None; if (flag6) { cell.InnerStyle = worksheetRangeStyle; cell.StyleParentKind = styleParentKind2; return; } bool flag7 = (flags & PlainStyleFlag.BackColor) == PlainStyleFlag.BackColor; if (flag7) { cell.InnerStyle.BackColor = Color.Transparent; } } StyleParentKind styleParentKind3 = styleParentKind; StyleParentKind styleParentKind4 = styleParentKind3; if (styleParentKind4 != StyleParentKind.Row) { worksheetRangeStyle = this.RootStyle; } else { bool flag8 = columnHeader.InnerStyle != null; if (flag8) { worksheetRangeStyle = columnHeader.InnerStyle; } else { worksheetRangeStyle = this.RootStyle; } } PlainStyleFlag plainStyleFlag2 = flags & worksheetRangeStyle.Flag; bool flag9 = plainStyleFlag2 > PlainStyleFlag.None; if (flag9) { StyleUtility.CopyStyle(worksheetRangeStyle, cell.InnerStyle, plainStyleFlag2); } cell.StyleParentKind = StyleParentKind.Own; bool flag10 = (flags & (PlainStyleFlag)2097215L) > PlainStyleFlag.None; if (flag10) { cell.FontDirty = true; } } public WorksheetRangeStyle GetRangeStyles(RangePosition range) { RangePosition rangePosition = this.FixRange(range); return this.GetCellStyles(range.StartPos); } internal object GetRangeStyle(int row, int col, int rows, int cols, PlainStyleFlag flag) { return this.GetCellStyleItem(row, col, flag); } public WorksheetRangeStyle GetCellStyles(string address) { bool flag = !CellPosition.IsValidAddress(address); if (flag) { throw new InvalidAddressException(address); } return this.GetCellStyles(new CellPosition(address)); } public WorksheetRangeStyle GetCellStyles(CellPosition pos) { return this.GetCellStyles(pos.Row, pos.Col); } public WorksheetRangeStyle GetCellStyles(int row, int col) { Cell cell = this.cells[row, col]; StyleParentKind styleParentKind = StyleParentKind.Own; bool flag = cell == null; WorksheetRangeStyle result; if (flag) { result = StyleUtility.FindCellParentStyle(this, row, col, out styleParentKind); } else { result = new WorksheetRangeStyle(cell.InnerStyle); } return result; } public object GetCellStyleItem(int row, int col, PlainStyleFlag flag) { Cell cell = this.cells[row, col]; StyleParentKind styleParentKind = StyleParentKind.Own; WorksheetRangeStyle style = (cell == null) ? StyleUtility.FindCellParentStyle(this, row, col, out styleParentKind) : cell.InnerStyle; return StyleUtility.GetStyleItem(style, flag); } private void UpdateCellBounds(Cell cell) { Debug.Assert(cell.Rowspan >= 1 && cell.Colspan >= 1); cell.Bounds = this.GetRangeBounds(cell.InternalRow, cell.InternalCol, (int)cell.Rowspan, (int)cell.Colspan); this.UpdateCellTextBounds(cell); cell.UpdateContentBounds(); } internal void UpdateCellFont(Cell cell, UpdateFontReason reason = UpdateFontReason.FontChanged) { this.UpdateCellRenderFont(null, cell, DrawMode.View, reason); } internal void UpdateCellRenderFont(IRenderer ir, Cell cell, DrawMode drawMode, UpdateFontReason reason) { bool flag = this.controlAdapter == null || cell.InnerStyle == null; if (!flag) { bool flag2 = string.IsNullOrEmpty(cell.InnerDisplay); if (!flag2) { bool flag3 = !(cell.Data is RichText); if (flag3) { bool flag4 = ir == null; if (flag4) { ir = this.controlAdapter.Renderer; } ir.UpdateCellRenderFont(cell, reason); } cell.FontDirty = false; this.UpdateCellTextBounds(ir, cell, drawMode, reason); } } } internal void UpdateCellTextBounds(Cell cell) { bool fontDirty = cell.FontDirty; if (fontDirty) { this.UpdateCellFont(cell, UpdateFontReason.FontChanged); } else { this.UpdateCellTextBounds(null, cell, DrawMode.View, UpdateFontReason.FontChanged); } } internal void UpdateCellTextBounds(IRenderer ig, Cell cell, DrawMode drawMode, UpdateFontReason reason) { this.UpdateCellTextBounds(ig, cell, drawMode, this.renderScaleFactor, reason); } internal void UpdateCellTextBounds(IRenderer ig, Cell cell, DrawMode drawMode, float scaleFactor, UpdateFontReason reason) { bool flag = cell == null || string.IsNullOrEmpty(cell.DisplayText); if (!flag) { bool flag2 = ig == null && this.controlAdapter != null; if (flag2) { ig = this.controlAdapter.Renderer; } bool flag3 = ig == null; if (!flag3) { bool flag4 = cell.Data is RichText; if (flag4) { RichText richText = (RichText)cell.Data; Size size = richText.TextSize; richText.TextWrap = cell.InnerStyle.TextWrapMode; richText.DefaultHorizontalAlignment = cell.Style.HAlign; richText.VerticalAlignment = cell.Style.VAlign; RichText richText2 = richText; float num = cell.Width - (float)cell.InnerStyle.Indent; float height = cell.Height; richText2.Size = new Size(ref num, ref height); Size size2 = richText.TextSize; } else { Size size = cell.TextBounds.Size; Size size2 = ig.MeasureCellText(cell, drawMode, scaleFactor); bool flag5 = size2.Width <= 0f || size2.Height <= 0f; if (!flag5) { size2.Width += 2f; size2.Height += 1f; Rect bounds = cell.Bounds; float num2 = bounds.Width * scaleFactor; bool flag6 = cell.InnerStyle.HAlign == ReoGridHorAlign.DistributedIndent; if (flag6) { float num = size2.Width; size2.Width = num - 1f; bool flag7 = drawMode == DrawMode.View; if (flag7) { cell.DistributedIndentSpacing = (num2 - size2.Width - 3f) / (float)(cell.DisplayText.Length - 1) - 1f; bool flag8 = cell.DistributedIndentSpacing < 0f; if (flag8) { cell.DistributedIndentSpacing = 0f; } } else { cell.DistributedIndentSpacingPrint = (num2 - size2.Width - 3f) / (float)(cell.DisplayText.Length - 1) - 1f; bool flag9 = cell.DistributedIndentSpacingPrint < 0f; if (flag9) { cell.DistributedIndentSpacingPrint = 0f; } } cell.RenderHorAlign = ReoGridRenderHorAlign.Center; bool flag10 = size2.Width < num2 - 1f; if (flag10) { size2.Width = (float)Math.Round((double)(num2 - 1f)); } } float num3 = 0f; float num4 = 0f; float num5 = (float)cell.InnerStyle.Indent; switch (cell.RenderHorAlign) { default: num3 = bounds.Left * scaleFactor + 2f + num5 * this.indentSize; break; case ReoGridRenderHorAlign.Center: num3 = bounds.Left * scaleFactor + num2 / 2f - size2.Width / 2f; break; case ReoGridRenderHorAlign.Right: num3 = bounds.Right * scaleFactor - 3f - size2.Width - num5 * this.indentSize; break; } switch (cell.InnerStyle.VAlign) { case ReoGridVerAlign.Top: num4 = bounds.Top * scaleFactor + 1f; goto IL_3AC; case ReoGridVerAlign.Middle: num4 = bounds.Top * scaleFactor + bounds.Height * scaleFactor / 2f - size2.Height / 2f; goto IL_3AC; } num4 = bounds.Bottom * scaleFactor - 1f - size2.Height; IL_3AC: if (drawMode == DrawMode.View || drawMode - DrawMode.Preview > 1) { float num = size2.Width; float height = size2.Height; cell.TextBounds = new Rect(ref num3, ref num4, ref num, ref height); } else { float num = size2.Width; float height = size2.Height; cell.PrintTextBounds = new Rect(ref num3, ref num4, ref num, ref height); } bool flag11 = drawMode == DrawMode.View && reason != UpdateFontReason.ScaleChanged; if (flag11) { bool flag12 = size2.Height > size.Height && this.settings.Has(WorksheetSettings.Edit_AutoExpandRowHeight); if (flag12) { RowHeader rowHeader = this.rows[cell.Row]; bool flag13 = rowHeader.IsVisible && rowHeader.IsAutoHeight; if (flag13) { cell.ExpandRowHeight(); } } bool flag14 = size2.Width > size.Width && this.settings.Has(WorksheetSettings.Edit_AutoExpandColumnWidth); if (flag14) { ColumnHeader columnHeader = this.cols[cell.Column]; bool flag15 = columnHeader.IsVisible && columnHeader.IsAutoWidth; if (flag15) { cell.ExpandColumnWidth(); } } } } } } } } public void StepRangeFont(RangePosition range, Func stepHandler) { RangePosition range2 = this.FixRange(range); bool enableAdjustRowHeight = this.settings.Has(WorksheetSettings.Edit_AutoExpandRowHeight | WorksheetSettings.Edit_AllowAdjustRowHeight); RowHeader rowHeader = null; this.IterateCells(range2, delegate(int r, int c, Cell cell) { cell.CreateOwnStyle(); float num = stepHandler(cell.InnerStyle.FontSize); bool flag = enableAdjustRowHeight && num > cell.InnerStyle.FontSize; if (flag) { cell.InnerStyle.FontSize = num; bool flag2 = rowHeader == null || rowHeader.Index != r; if (flag2) { rowHeader = this.rows[r]; bool isAutoHeight = rowHeader.IsAutoHeight; if (isAutoHeight) { cell.ExpandRowHeight(); } } } else { cell.InnerStyle.FontSize = num; } cell.FontDirty = true; return true; }); this.RequestInvalidate(); } internal WorksheetRangeStyle RootStyle { get; set; } public void SuspendUIUpdates() { this.suspendingUIUpdates = true; } public void ResumeUIUpdates() { bool flag = this.suspendingUIUpdates; if (flag) { this.suspendingUIUpdates = false; this.RequestInvalidate(); } } public bool IsUIUpdatesSuspending { get { return this.suspendingUIUpdates; } } internal IViewportController ViewportController { get { return this.viewportController; } set { this.viewportController = value; } } internal void UpdateViewportController() { bool flag = this.suspendingUIUpdates; if (!flag) { Stopwatch stopwatch = Stopwatch.StartNew(); this.AutoAdjustRowHeaderPanelWidth(); bool flag2 = this.viewportController != null; if (flag2) { this.viewportController.UpdateController(); bool isFrozen = this.IsFrozen; if (isFrozen) { this.FreezeToCell(this.FreezePos, this.FreezeArea); } } bool flag3 = this.HasSettings(WorksheetSettings.View_ShowPageBreaks) && this.rows.Count > 0 && this.cols.Count > 0; if (flag3) { this.AutoSplitPage(); } stopwatch.Stop(); long elapsedMilliseconds = stopwatch.ElapsedMilliseconds; bool flag4 = elapsedMilliseconds > 15L; if (flag4) { Debug.WriteLine("updating viewport controller takes " + stopwatch.ElapsedMilliseconds.ToString() + " ms."); } } } internal void UpdateViewportControllBounds() { bool flag = this.viewportController != null && this.controlAdapter != null; if (flag) { this.viewportController.Bounds = this.controlAdapter.GetContainerBounds(); this.viewportController.UpdateController(); } } public void RequestInvalidate() { bool flag = !this.viewDirty && !this.suspendingUIUpdates; if (flag) { this.viewDirty = true; bool flag2 = this.controlAdapter != null; if (flag2) { this.controlAdapter.Invalidate(); } } } public ReoGridViewMode ViewMode { get; set; } public bool StartEdit() { return !this.selStart.IsEmpty && this.StartEdit(this.focusPos); } public bool StartEdit(string newText) { return !this.selStart.IsEmpty && this.StartEdit(this.focusPos, newText); } public bool StartEdit(CellPosition pos) { return this.StartEdit(pos.Row, pos.Col); } public bool StartEdit(CellPosition pos, string newText) { return this.StartEdit(pos.Row, pos.Col, newText); } public bool StartEdit(int row, int col) { bool flag = row < 0 || col < 0 || row >= this.rows.Count || col >= this.cols.Count; bool result; if (flag) { result = false; } else { bool flag2 = !this.IsValidCell(row, col); if (flag2) { Cell mergedCellOfRange = this.GetMergedCellOfRange(row, col); result = this.StartEdit(mergedCellOfRange); } else { result = this.StartEdit(this.CreateAndGetCell(row, col)); } } return result; } public bool StartEdit(int row, int col, string newText) { bool flag = row < 0 || col < 0 || row >= this.cells.RowCapacity || col >= this.cells.ColCapacity; bool result; if (flag) { result = false; } else { bool flag2 = !this.IsValidCell(row, col); if (flag2) { Cell mergedCellOfRange = this.GetMergedCellOfRange(row, col); result = this.StartEdit(mergedCellOfRange, newText); } else { result = this.StartEdit(this.CreateAndGetCell(row, col), newText); } } return result; } internal bool StartEdit(Cell cell) { return this.StartEdit(cell, null); } internal bool StartEdit(Cell cell, string newText) { bool flag = this.HasSettings(WorksheetSettings.Edit_Readonly) || cell == null || cell.IsReadOnly; bool result; if (flag) { result = false; } else { bool flag2 = this.focusPos != cell.Position; if (flag2) { this.FocusPos = cell.Position; } else { this.ScrollToCell(cell); } bool flag3 = newText == null; string text; if (flag3) { bool flag4 = !string.IsNullOrEmpty(cell.InnerFormula); if (flag4) { text = "=" + cell.InnerFormula; } else { bool flag5 = cell.InnerData is string; if (flag5) { text = (string)cell.InnerData; } else { bool flag6 = cell.InnerData is RichText; if (flag6) { text = ((RichText)cell.InnerData).ToString(); } else { text = Convert.ToString(cell.InnerData); } } } this.backupData = text; } else { text = newText; this.backupData = cell.DisplayText; } bool flag7 = cell.DataFormat == CellDataFormatFlag.Percent && this.HasSettings(WorksheetSettings.Edit_FriendlyPercentInput); if (flag7) { double num; bool flag8 = double.TryParse(text, out num); if (flag8) { text = ((newText == null) ? (num * 100.0) : num).ToString() + "%"; } } bool flag9 = this.BeforeCellEdit != null; if (flag9) { CellBeforeEditEventArgs cellBeforeEditEventArgs = new CellBeforeEditEventArgs(cell) { EditText = text }; this.BeforeCellEdit(this, cellBeforeEditEventArgs); bool isCancelled = cellBeforeEditEventArgs.IsCancelled; if (isCancelled) { return false; } text = cellBeforeEditEventArgs.EditText; } bool flag10 = cell.body != null; if (flag10) { bool flag11 = cell.body.OnStartEdit(); bool flag12 = !flag11; if (flag12) { return false; } } bool flag13 = this.currentEditingCell != null; if (flag13) { this.EndEdit(this.controlAdapter.GetEditControlText()); } this.currentEditingCell = cell; this.controlAdapter.SetEditControlText(text); bool flag14 = cell.DataFormat == CellDataFormatFlag.Percent && text.EndsWith("%"); if (flag14) { this.controlAdapter.SetEditControlCaretPos(text.Length - 1); } float num2 = (cell.Width - 1f) * this.renderScaleFactor; int num3 = 0; bool flag15 = num2 < cell.TextBounds.Width; if (flag15) { num2 = cell.TextBounds.Width + 6f; } num2 -= 1f; float num4 = this.renderScaleFactor; float num5; switch (cell.RenderHorAlign) { default: this.controlAdapter.SetEditControlAlignment(ReoGridHorAlign.Left); num5 = cell.Left * num4 + 1f + (float)num3; break; case ReoGridRenderHorAlign.Center: this.controlAdapter.SetEditControlAlignment(ReoGridHorAlign.Center); num5 = cell.Left * num4 + ((cell.Width - 1f) * num4 - 1f - num2) / 2f + 1f; break; case ReoGridRenderHorAlign.Right: this.controlAdapter.SetEditControlAlignment(ReoGridHorAlign.Right); num5 = (cell.Right - 1f) * num4 - num2 - (float)num3; break; } bool flag16 = cell.InnerStyle.HAlign == ReoGridHorAlign.DistributedIndent; if (flag16) { this.controlAdapter.SetEditControlAlignment(ReoGridHorAlign.Center); } float num6 = cell.Top * num4 + 1f; IViewport viewport = this.viewportController.FocusView as IViewport; int num7 = (int)Math.Round((double)(num5 + this.viewportController.FocusView.Left - ((viewport == null) ? 0f : (viewport.ScrollViewLeft * num4)))); int num8 = (int)Math.Round((double)(num6 + this.viewportController.FocusView.Top - ((viewport == null) ? 0f : (viewport.ScrollViewTop * num4)))); float num9 = (cell.Height - 1f) * num4 - 1f; bool flag17 = !cell.IsMergedCell && cell.InnerStyle.TextWrapMode > TextWrapMode.NoWrap; if (flag17) { bool flag18 = num9 < cell.TextBounds.Height; if (flag18) { num9 = cell.TextBounds.Height; } } int num10 = 0; bool flag19 = num10 > 0; if (flag19) { switch (cell.InnerStyle.VAlign) { case ReoGridVerAlign.Top: goto IL_498; case ReoGridVerAlign.Bottom: num8 -= num10; goto IL_498; } num8 -= num10 / 2; IL_498:; } float num11 = (float)num7; float num12 = (float)num8; Rect bounds = new Rect(ref num11, ref num12, ref num2, ref num9); this.controlAdapter.ShowEditControl(bounds, cell); result = true; } return result; } public bool IsEditing { get { return this.currentEditingCell != null; } } public Cell EditingCell { get { return this.currentEditingCell; } } public bool EndEdit(EndEditReason reason) { return this.EndEdit((reason == EndEditReason.NormalFinish) ? this.controlAdapter.GetEditControlText() : null, reason); } public bool EndEdit(object data) { return this.EndEdit(data, EndEditReason.NormalFinish); } public bool EndEdit(object data, EndEditReason reason) { bool flag = this.currentEditingCell == null || this.endEditProcessing; bool result; if (flag) { result = false; } else { this.endEditProcessing = true; bool flag2 = data == null; if (flag2) { data = this.controlAdapter.GetEditControlText(); } bool flag3 = this.AfterCellEdit != null; if (flag3) { CellAfterEditEventArgs cellAfterEditEventArgs = new CellAfterEditEventArgs(this.currentEditingCell) { EndReason = reason, NewData = data }; this.AfterCellEdit(this, cellAfterEditEventArgs); data = cellAfterEditEventArgs.NewData; reason = cellAfterEditEventArgs.EndReason; } EndEditReason endEditReason = reason; EndEditReason endEditReason2 = endEditReason; if (endEditReason2 != EndEditReason.NormalFinish) { if (endEditReason2 != EndEditReason.Cancel) { } } else { bool flag4 = data is string; if (flag4) { string text = (string)data; bool flag5 = string.IsNullOrEmpty(text); if (flag5) { data = null; } else { switch (this.currentEditingCell.DataFormat) { case CellDataFormatFlag.Number: case CellDataFormatFlag.Currency: { double num; bool flag6 = double.TryParse(text, out num); if (flag6) { data = num; } break; } case CellDataFormatFlag.DateTime: { DateTime dateTime; bool flag7 = DateTime.TryParse(text, out dateTime); if (flag7) { data = dateTime; } break; } case CellDataFormatFlag.Percent: { bool flag8 = text.EndsWith("%"); if (flag8) { double num2; bool flag9 = double.TryParse(text.Substring(0, text.Length - 1), out num2); if (flag9) { data = num2 / 100.0; } } else { bool flag10 = text == "%"; if (flag10) { data = null; } } break; } } } } bool flag11 = string.IsNullOrEmpty(this.backupData); if (flag11) { this.backupData = null; } ICellBody body = this.currentEditingCell.body; bool flag12 = body != null; if (flag12) { data = body.OnEndEdit(data); } bool flag13 = !object.Equals(data, this.backupData); if (flag13) { this.DoAction(new SetCellDataAction(this.currentEditingCell.InternalRow, this.currentEditingCell.InternalCol, data)); } } this.controlAdapter.HideEditControl(); this.controlAdapter.Focus(); this.currentEditingCell = null; this.endEditProcessing = false; result = true; } return result; } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler BeforeCellEdit; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler AfterCellEdit; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler CellEditTextChanging; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler CellEditCharInputed; internal string RaiseCellEditTextChanging(string text) { bool flag = this.CellEditTextChanging == null; string result; if (flag) { result = text; } else { CellEditTextChangingEventArgs cellEditTextChangingEventArgs = new CellEditTextChangingEventArgs(this.currentEditingCell) { Text = text }; this.CellEditTextChanging(this, cellEditTextChangingEventArgs); result = cellEditTextChangingEventArgs.Text; } return result; } internal int RaiseCellEditCharInputed(int @char) { bool flag = this.CellEditCharInputed == null; int result; if (flag) { result = @char; } else { CellEditCharInputEventArgs cellEditCharInputEventArgs = new CellEditCharInputEventArgs(this.currentEditingCell, (this.currentEditingCell != null) ? this.controlAdapter.GetEditControlText() : null, @char, this.controlAdapter.GetEditControlCaretPos()); this.CellEditCharInputed(this, cellEditCharInputEventArgs); result = cellEditCharInputEventArgs.InputChar; } return result; } public string CellEditText { get { return this.controlAdapter.GetEditControlText(); } set { this.controlAdapter.SetEditControlText(value); } } private void InitGrid() { this.InitGrid(200, 100); } private void InitGrid(int rows, int cols) { Stopwatch stopwatch = Stopwatch.StartNew(); Debug.WriteLine("start creating worksheet..."); this.colHeaderHeight = MeasureToolkit.ScaleByDPI(this.colHeaderHeight); this.rowHeaderWidth = MeasureToolkit.ScaleByDPI(this.rowHeaderWidth); this.defaultRowHeight = MeasureToolkit.ScaleByDPI(this.defaultRowHeight); this.defaultColumnWidth = MeasureToolkit.ScaleByDPI(this.defaultColumnWidth); this.SuspendUIUpdates(); this.Resize(rows, cols); bool flag = this.controlAdapter != null; if (flag) { this.renderScaleFactor = this._scaleFactor + this.controlAdapter.BaseScale; IScalableViewportController scalableViewportController = this.viewportController as IScalableViewportController; bool flag2 = scalableViewportController != null; if (flag2) { scalableViewportController.ScaleFactor = this.renderScaleFactor; } } this.RootStyle = new WorksheetRangeStyle(Worksheet.DefaultStyle); this.settings = WorksheetSettings.Default; this.selectionRange = new RangePosition(0, 0, 1, 1); bool flag3 = this.printSettings != null; if (flag3) { this.printSettings = null; } this.drawingCanvas = new WorksheetDrawingCanvas(this); this.ResumeUIUpdates(); bool flag4 = this.viewportController != null; if (flag4) { this.viewportController.Reset(); } stopwatch.Stop(); long elapsedMilliseconds = stopwatch.ElapsedMilliseconds; bool flag5 = elapsedMilliseconds > 10L; if (flag5) { Debug.WriteLine("creating worksheet done: " + elapsedMilliseconds.ToString() + " ms."); } } internal void Clear() { this.EndEdit(EndEditReason.Cancel); this.endEditProcessing = false; bool flag = this.controlAdapter != null; if (flag) { IActionControl actionControl = this.controlAdapter.ControlInstance as IActionControl; bool flag2 = actionControl != null; if (flag2) { actionControl.ClearActionHistoryForWorksheet(this); } } bool flag3 = this.outlines != null; if (flag3) { this.ClearOutlines(RowOrColumn.Both); } this.registeredNamedRanges.Clear(); bool flag4 = this.highlightRanges != null; if (flag4) { this.highlightRanges.Clear(); } bool flag5 = this.pageBreakRows != null; if (flag5) { this.pageBreakRows.Clear(); } bool flag6 = this.pageBreakCols != null; if (flag6) { this.pageBreakCols.Clear(); } bool flag7 = this.userPageBreakRows != null; if (flag7) { this.userPageBreakRows.Clear(); } bool flag8 = this.userPageBreakCols != null; if (flag8) { this.userPageBreakCols.Clear(); } this.printableRange = RangePosition.Empty; this.printSettings = null; bool flag9 = this.drawingCanvas != null; if (flag9) { this.drawingCanvas.Children.Clear(); } this.defaultColumnWidth = Worksheet.InitDefaultColumnWidth; this.defaultRowHeight = Worksheet.InitDefaultRowHeight; this.RootStyle = new WorksheetRangeStyle(Worksheet.DefaultStyle); this.FocusHighlightRange = null; this.operationStatus = OperationStatus.Default; this.settings = WorksheetSettings.Default; bool flag10 = this.SettingsChanged != null; if (flag10) { this.SettingsChanged(this, null); } this.formulaRanges.Clear(); bool flag11 = this.traceDependentArrows != null; if (flag11) { this.traceDependentArrows.Clear(); } CellPosition freezePos = this.FreezePos; bool flag12 = freezePos.Row > 0 || freezePos.Col > 0; if (flag12) { this.Unfreeze(); } bool flag13 = this.viewportController != null; if (flag13) { this.viewportController.Reset(); } this.cells = new Index4DArray(); this.hBorders = new Index4DArray(); this.vBorders = new Index4DArray(); this.rows.Clear(); this.cols.Clear(); this.maxRowHeader = -1; this.maxColumnHeader = -1; this.rangeHighlightColorCounter = 0; } public void Reset() { this.Reset(200, 100); } public void Reset(int rows, int cols) { this.EndEdit(EndEditReason.Cancel); this._scaleFactor = 1f; this.Clear(); bool flag = this.controlAdapter != null; if (flag) { IActionControl actionControl = this.controlAdapter.ControlInstance as IActionControl; bool flag2 = actionControl != null; if (flag2) { actionControl.ClearActionHistoryForWorksheet(this); } } this.defaultRowHeight = Worksheet.InitDefaultRowHeight; this.defaultColumnWidth = Worksheet.InitDefaultColumnWidth; this.userRowHeaderWidth = false; this.settings = WorksheetSettings.View_Default; this.InitGrid(rows, cols); this.RequestInvalidate(); bool flag3 = this.Resetted != null; if (flag3) { this.Resetted(this, null); } } internal int FindColIndexMiddle(float x) { return ArrayHelper.QuickFind(0, this.cols.Count, delegate(int i) { ColumnHeader columnHeader = this.cols[i]; bool flag = x > (float)(columnHeader.Left + (int)(columnHeader.InnerWidth / 2)); int result; if (flag) { result = 1; } else { bool flag2 = i > 0; if (flag2) { ColumnHeader columnHeader2 = this.cols[i - 1]; bool flag3 = x < (float)(columnHeader2.Left + (int)(columnHeader2.InnerWidth / 2)); if (flag3) { return -1; } } result = 0; } return result; }); } internal int FindRowIndexMiddle(float x) { return ArrayHelper.QuickFind(0, this.rows.Count, delegate(int i) { RowHeader rowHeader = this.rows[i]; bool flag = x > (float)(rowHeader.Top + (int)(rowHeader.InnerHeight / 2)); int result; if (flag) { result = 1; } else { bool flag2 = i > 0; if (flag2) { RowHeader rowHeader2 = this.rows[i - 1]; bool flag3 = x < (float)(rowHeader2.Top + (int)(rowHeader2.InnerHeight / 2)); if (flag3) { return -1; } } result = 0; } return result; }); } internal bool FindColumnByPosition(float x, out int col) { int num = -1; bool result = true; float num2 = 2f / this.renderScaleFactor; for (int i = 0; i < this.cols.Count; i++) { bool flag = x <= (float)this.cols[i].Right - num2; if (flag) { result = false; num = i; break; } bool flag2 = x <= (float)this.cols[i].Right + num2; if (flag2) { num = i; break; } } col = num; return result; } internal bool FindRowByPosition(float y, out int row) { int num = -1; bool result = true; float num2 = 2f / this.renderScaleFactor; for (int i = 0; i < this.rows.Count; i++) { bool flag = y <= (float)this.rows[i].Bottom - num2; if (flag) { result = false; num = i; break; } bool flag2 = y <= (float)this.rows[i].Bottom + num2; if (flag2) { num = i; break; } } row = num; return result; } internal Rect GetRangeBounds(int row, int col, int rows, int cols) { return this.GetRangePhysicsBounds(new RangePosition(row, col, rows, cols)); } internal Rect GetRangeBounds(CellPosition startPos, CellPosition endPos) { return this.GetRangePhysicsBounds(new RangePosition(startPos, endPos)); } public Rect GetRangePhysicsBounds(RangePosition range) { RangePosition rangePosition = this.FixRange(range); RowHeader rowHeader = this.rows[rangePosition.Row]; ColumnHeader columnHeader = this.cols[rangePosition.Col]; RowHeader rowHeader2 = this.rows[rangePosition.EndRow]; ColumnHeader columnHeader2 = this.cols[rangePosition.EndCol]; int num = columnHeader2.Right - columnHeader.Left; int num2 = rowHeader2.Bottom - rowHeader.Top; float num3 = (float)columnHeader.Left; float num4 = (float)rowHeader.Top; float num5 = (float)(num + 1); float num6 = (float)(num2 + 1); return new Rect(ref num3, ref num4, ref num5, ref num6); } public Point GetCellPhysicsPosition(int row, int col) { bool flag = row < 0 || row >= this.rows.Count || col < 0 || col >= this.cols.Count; if (flag) { throw new ArgumentException("row or col invalid"); } int top = this.rows[row].Top; int left = this.cols[col].Left; float num = (float)left; float num2 = (float)top; return new Point(ref num, ref num2); } internal Rect GetScaledRangeBounds(RangePosition range) { RowHeader rowHeader = this.rows[range.Row]; ColumnHeader columnHeader = this.cols[range.Col]; RowHeader rowHeader2 = this.rows[range.EndRow]; ColumnHeader columnHeader2 = this.cols[range.EndCol]; float num = (float)(columnHeader2.Right - columnHeader.Left) * this.renderScaleFactor; float num2 = (float)(rowHeader2.Bottom - rowHeader.Top) * this.renderScaleFactor; float num3 = (float)columnHeader.Left * this.renderScaleFactor; float num4 = (float)rowHeader.Top * this.renderScaleFactor; return new Rect(ref num3, ref num4, ref num, ref num2); } internal Rect GetCellBounds(CellPosition pos) { return this.GetCellBounds(pos.Row, pos.Col); } internal Rect GetCellBounds(int row, int col) { bool flag = this.cells[row, col] == null; Rect result; if (flag) { result = this.GetCellRectFromHeader(row, col); } else { bool flag2 = this.cells[row, col].MergeStartPos != CellPosition.Empty; if (flag2) { Cell cell = this.GetCell(this.cells[row, col].MergeStartPos); result = ((cell != null) ? cell.Bounds : this.GetCellRectFromHeader(row, col)); } else { result = this.cells[row, col].Bounds; } } return result; } private Rect GetCellRectFromHeader(int row, int col) { float num = (float)this.cols[col].Left; float num2 = (float)this.rows[row].Top; float num3 = (float)(this.cols[col].InnerWidth + 1); float num4 = (float)(this.rows[row].InnerHeight + 1); return new Rect(ref num, ref num2, ref num3, ref num4); } public CellPosition FocusPos { get { return this.focusPos; } set { bool flag = this.focusPos != value; if (flag) { CellPosition r = this.FixPos(value); bool flag2 = !r.IsEmpty; if (flag2) { Cell cell = this.cells[r.Row, r.Col]; bool flag3 = cell != null; if (flag3) { bool flag4 = !cell.IsValidCell; if (flag4) { r = this.GetMergedCellOfRange(cell).InternalPos; } } } bool flag5 = this.focusPos != r; if (flag5) { bool flag6 = !this.focusPos.IsEmpty; if (flag6) { Cell cell2 = this.cells[this.focusPos.Row, this.focusPos.Col]; bool flag7 = cell2 != null && cell2.body != null; if (flag7) { cell2.body.OnLostFocus(); } } this.focusPos = r; bool flag8 = !this.focusPos.IsEmpty; if (flag8) { Cell cell3 = this.cells[this.focusPos.Row, this.focusPos.Col]; bool flag9 = cell3 != null && cell3.body != null && cell3.IsValidCell; if (flag9) { cell3.body.OnGotFocus(); } bool flag10 = !this.selectionRange.Contains(this.focusPos); if (flag10) { this.SelectRange(this.focusPos.Row, this.FocusPos.Col, 1, 1); } } this.RequestInvalidate(); EventHandler focusPosChanged = this.FocusPosChanged; if (focusPosChanged != null) { focusPosChanged(this, new CellPosEventArgs(this.focusPos)); } } } } } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler FocusPosChanged; public FocusPosStyle FocusPosStyle { get { return this.focusPosStyle; } set { bool flag = this.focusPosStyle != value; if (flag) { this.RequestInvalidate(); this.focusPosStyle = value; EventHandler focusPosStyleChanged = this.FocusPosStyleChanged; if (focusPosStyleChanged != null) { focusPosStyleChanged(this, null); } } } } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler FocusPosStyleChanged; public CellPosition HoverPos { get { return this.hoverPos; } internal set { bool flag = this.hoverPos != value; if (flag) { bool flag2 = !this.hoverPos.IsEmpty; if (flag2) { CellMouseEventArgs cellMouseEventArgs = null; bool flag3 = this.CellMouseLeave != null; if (flag3) { cellMouseEventArgs = new CellMouseEventArgs(this, this.hoverPos); this.CellMouseLeave(this, cellMouseEventArgs); } Cell cell = this.cells[this.hoverPos.Row, this.hoverPos.Col]; bool flag4 = cell != null; if (flag4) { bool flag5 = !cell.IsValidCell; if (flag5) { cell = this.GetMergedCellOfRange(cell); } bool flag6 = cell.body != null; if (flag6) { bool flag7 = cellMouseEventArgs == null; if (flag7) { cellMouseEventArgs = new CellMouseEventArgs(this, cell); } bool flag8 = cell.body.OnMouseLeave(cellMouseEventArgs); bool flag9 = flag8; if (flag9) { this.RequestInvalidate(); } } } } this.hoverPos = value; bool flag10 = !this.hoverPos.IsEmpty; if (flag10) { CellMouseEventArgs cellMouseEventArgs2 = null; bool flag11 = this.CellMouseEnter != null; if (flag11) { cellMouseEventArgs2 = new CellMouseEventArgs(this, this.hoverPos); this.CellMouseEnter(this, cellMouseEventArgs2); } Cell cell2 = this.cells[this.hoverPos.Row, this.hoverPos.Col]; bool flag12 = cell2 != null; if (flag12) { bool flag13 = !cell2.IsValidCell; if (flag13) { cell2 = this.GetMergedCellOfRange(cell2); } bool flag14 = cell2.body != null; if (flag14) { bool flag15 = cellMouseEventArgs2 == null; if (flag15) { cellMouseEventArgs2 = new CellMouseEventArgs(this, cell2); cellMouseEventArgs2.Cell = cell2; } bool flag16 = cell2.body.OnMouseEnter(cellMouseEventArgs2); bool flag17 = flag16; if (flag17) { this.RequestInvalidate(); } } } } EventHandler hoverPosChanged = this.HoverPosChanged; if (hoverPosChanged != null) { hoverPosChanged(this, new CellPosEventArgs(this.hoverPos)); } } } } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler HoverPosChanged; public RangePosition SelectionRange { get { return this.selectionRange; } set { this.SelectRange(value); } } [DefaultValue(WorksheetSelectionMode.Range)] public WorksheetSelectionMode SelectionMode { get { return this.selectionMode; } set { bool flag = this.selectionMode != value; if (flag) { bool isEditing = this.IsEditing; if (isEditing) { this.EndEdit(EndEditReason.NormalFinish); } WorksheetSelectionMode worksheetSelectionMode = this.selectionMode; this.selectionMode = value; WorksheetSelectionMode worksheetSelectionMode2 = worksheetSelectionMode; WorksheetSelectionMode worksheetSelectionMode3 = worksheetSelectionMode2; if (worksheetSelectionMode3 != WorksheetSelectionMode.None) { switch (value) { case WorksheetSelectionMode.None: this.selectionRange = RangePosition.Empty; this.focusPos = CellPosition.Empty; this.RequestInvalidate(); break; case WorksheetSelectionMode.Cell: this.SelectRange(this.selStart.Row, this.selStart.Col, 1, 1); break; case WorksheetSelectionMode.Range: this.SelectionRange = this.FixRangeSelection(this.selectionRange); break; } } else if (value - WorksheetSelectionMode.Cell <= 1) { this.SelectRange(new RangePosition(0, 0, 1, 1)); } switch (this.selectionMode) { case WorksheetSelectionMode.Row: case WorksheetSelectionMode.SingleRow: this.SelectRange(this.selectionRange.Row, 0, this.selectionRange.Rows, -1); break; case WorksheetSelectionMode.Column: case WorksheetSelectionMode.SingleColumn: this.SelectRange(0, this.selectionRange.Col, -1, this.selectionRange.Cols); break; } bool flag2 = this.SelectionModeChanged != null; if (flag2) { this.SelectionModeChanged(this, null); } } } } [DefaultValue(WorksheetSelectionStyle.Default)] public WorksheetSelectionStyle SelectionStyle { get { return this.selectionStyle; } set { bool flag = this.selectionStyle != value; if (flag) { this.selectionStyle = value; this.RequestInvalidate(); EventHandler selectionStyleChanged = this.SelectionStyleChanged; if (selectionStyleChanged != null) { selectionStyleChanged(this, null); } } } } [DefaultValue(SelectionForwardDirection.Right)] public SelectionForwardDirection SelectionForwardDirection { get { return this.selectionForwardDirection; } set { bool flag = this.selectionForwardDirection != value; if (flag) { this.selectionForwardDirection = value; EventHandler selectionForwardDirectionChanged = this.SelectionForwardDirectionChanged; if (selectionForwardDirectionChanged != null) { selectionForwardDirectionChanged(this, null); } } } } internal void SelectRangeStartByMouse(Point location, InputModifiers modifiers) { bool flag = this.viewportController == null || this.viewportController.View == null; if (!flag) { bool flag2 = !modifiers.HasFlag(InputModifiers.Shift); if (flag2) { IRangeSelectableView rangeSelectableView = this.viewportController.View.GetViewByPoint(location) as IRangeSelectableView; bool flag3 = rangeSelectableView == null; if (flag3) { rangeSelectableView = (this.viewportController.FocusView as IRangeSelectableView); } bool flag4 = rangeSelectableView != null; if (flag4) { Point p = rangeSelectableView.PointToView(location); CellPosition posByPoint = CellsViewport.GetPosByPoint(rangeSelectableView, p); this.selEnd = (this.selStart = posByPoint); } } this.SelectRangeEndByMouse(location); } } internal void SelectRangeEndByMouse(Point location) { bool flag = this.viewportController == null || this.viewportController.View == null; if (!flag) { IRangeSelectableView rangeSelectableView = this.viewportController.View.GetViewByPoint(location) as IRangeSelectableView; bool flag2 = rangeSelectableView == null; if (flag2) { rangeSelectableView = (this.viewportController.FocusView as IRangeSelectableView); } bool flag3 = rangeSelectableView != null; if (flag3) { Point p = rangeSelectableView.PointToView(location); CellPosition start = this.selStart; CellPosition posByPoint = this.selEnd; OperationStatus operationStatus = this.operationStatus; OperationStatus operationStatus2 = operationStatus; if (operationStatus2 != OperationStatus.FullRowSelect) { if (operationStatus2 != OperationStatus.FullColumnSelect) { posByPoint = CellsViewport.GetPosByPoint(rangeSelectableView, p); } else { int num = -1; this.FindColumnByPosition(p.X, out num); bool flag4 = num > -1; if (flag4) { start = new CellPosition(0, start.Col); posByPoint = new CellPosition(this.rows.Count, num); } } } else { int num2 = -1; this.FindRowByPosition(p.Y, out num2); bool flag5 = num2 > -1; if (flag5) { start = new CellPosition(start.Row, 0); posByPoint = new CellPosition(num2, this.cols.Count); } } this.ApplyRangeSelection(start, posByPoint, true); } } } private RangePosition FixRangeSelection(RangePosition range) { bool isEmpty = range.IsEmpty; RangePosition result; if (isEmpty) { result = RangePosition.Empty; } else { Stopwatch stopwatch = Stopwatch.StartNew(); RangePosition rangePosition = this.FixRange(range); int num = rangePosition.Row; int num2 = rangePosition.Col; int num3 = rangePosition.EndRow; int num4 = rangePosition.EndCol; switch (this.selectionMode) { case WorksheetSelectionMode.Cell: num = (num3 = range.Row); num2 = (num4 = range.Col); break; case WorksheetSelectionMode.Row: num2 = 0; num4 = this.cols.Count - 1; break; case WorksheetSelectionMode.Column: num = 0; num3 = this.rows.Count - 1; break; } bool flag = (this.selectionMode == WorksheetSelectionMode.Cell || this.selectionMode == WorksheetSelectionMode.Range) && ((rangePosition.Cols < this.cols.Count && rangePosition.Rows < this.rows.Count) || this.cols.Count == 1 || this.rows.Count == 1); if (flag) { RangePosition rangePosition2 = this.CheckMergedRange(new RangePosition(num, num2, num3 - num + 1, num4 - num2 + 1)); num = rangePosition2.Row; num2 = rangePosition2.Col; num3 = rangePosition2.EndRow; num4 = rangePosition2.EndCol; } int num5 = num3 - num + 1; int num6 = num4 - num2 + 1; stopwatch.Stop(); bool flag2 = stopwatch.ElapsedMilliseconds > 25L; if (flag2) { Debug.WriteLine("select range takes " + stopwatch.ElapsedMilliseconds.ToString() + " ms."); } result = new RangePosition(num, num2, num5, num6); } return result; } private void MoveRangeSelection(CellPosition start, CellPosition end, bool appendSelect, bool scrollToSelectionEnd = true) { bool flag = !appendSelect; if (flag) { start = end; } this.ApplyRangeSelection(start, end, scrollToSelectionEnd); } private void ApplyRangeSelection(CellPosition start, CellPosition end, bool scrollToSelectionEnd = true) { OperationStatus operationStatus = this.operationStatus; OperationStatus operationStatus2 = operationStatus; bool flag; if (operationStatus2 != OperationStatus.HighlightRangeCreate) { this.ChangeSelectionRange(start, end); flag = true; } else { RangePosition rangePosition = this.FixRangeSelection(new RangePosition(start, end)); bool flag2 = this.focusHighlightRange == null; if (flag2) { HighlightRange highlightRange = this.AddHighlightRange(rangePosition); this.FocusHighlightRange = highlightRange; } else { bool flag3 = this.focusHighlightRange.Position != rangePosition; if (flag3) { this.focusHighlightRange.Position = rangePosition; this.RequestInvalidate(); } } flag = true; } bool flag4 = flag; if (flag4) { bool flag5 = this.HasSettings(WorksheetSettings.Behavior_ScrollToFocusCell) && scrollToSelectionEnd; if (flag5) { bool flag6 = start.Row != 0 || start.Col != 0 || this.selEnd.Row != this.rows.Count - 1 || this.selEnd.Col != this.cols.Count - 1; if (flag6) { this.ScrollToCell(this.selEnd); } } } } private void ChangeSelectionRange(CellPosition start, CellPosition end) { RangePosition r = this.FixRangeSelection(new RangePosition(start, end)); bool flag = this.selectionRange != r; if (flag) { bool flag2 = this.BeforeSelectionRangeChange != null; if (flag2) { BeforeSelectionChangeEventArgs beforeSelectionChangeEventArgs = new BeforeSelectionChangeEventArgs(start, end); this.BeforeSelectionRangeChange(this, beforeSelectionChangeEventArgs); bool isCancelled = beforeSelectionChangeEventArgs.IsCancelled; if (isCancelled) { return; } bool flag3 = start != beforeSelectionChangeEventArgs.SelectionStart || end != beforeSelectionChangeEventArgs.SelectionEnd; if (flag3) { start = beforeSelectionChangeEventArgs.SelectionStart; end = beforeSelectionChangeEventArgs.SelectionEnd; r = this.FixRangeSelection(new RangePosition(start, end)); } } this.selectionRange = r; this.selStart = start; this.selEnd = end; bool flag4 = this.focusPos.IsEmpty || !r.Contains(this.focusPos) || !this.IsValidCell(this.focusPos); if (flag4) { CellPosition cellPosition = this.selStart; for (int i = r.Row; i <= r.EndRow; i++) { for (int j = r.Col; j <= r.EndCol; j++) { Cell cell = this.cells[i, j]; bool flag5 = cell != null && (cell.Colspan <= 0 || cell.Rowspan <= 0); if (!flag5) { cellPosition.Row = i; cellPosition.Col = j; goto IL_191; } } } IL_191: bool flag6 = cellPosition.Col < this.cols.Count && cellPosition.Row < this.rows.Count; if (flag6) { this.FocusPos = cellPosition; } } this.focusReturnColumn = end.Col; bool flag7 = this.operationStatus == OperationStatus.RangeSelect; if (flag7) { EventHandler selectionRangeChanging = this.SelectionRangeChanging; if (selectionRangeChanging != null) { selectionRangeChanging(this, new RangeEventArgs(this.selectionRange)); } } else { EventHandler selectionRangeChanged = this.SelectionRangeChanged; if (selectionRangeChanged != null) { selectionRangeChanged(this, new RangeEventArgs(this.selectionRange)); } } this.RequestInvalidate(); } } public void SelectRange(string address) { bool flag = RangePosition.IsValidAddress(address); if (flag) { this.SelectRange(new RangePosition(address)); } else { bool flag2 = RGUtility.IsValidName(address); if (flag2) { NamedRange refRange; bool flag3 = this.registeredNamedRanges.TryGetValue(address, out refRange); if (flag3) { this.SelectRange(refRange); } } } } public void SelectRange(CellPosition pos1, CellPosition pos2) { this.SelectRange(new RangePosition(pos1, pos2)); } public void SelectRange(int row, int col, int rows, int cols) { this.SelectRange(new RangePosition(row, col, rows, cols)); } public void SelectRange(RangePosition range) { bool flag = range.IsEmpty || this.selectionMode == WorksheetSelectionMode.None; if (!flag) { range = this.FixRange(range); this.ApplyRangeSelection(range.StartPos, range.EndPos, false); } } public void SelectAll() { bool isEditing = this.IsEditing; if (isEditing) { this.controlAdapter.EditControlSelectAll(); } else { this.SelectRange(new RangePosition(0, 0, this.RowCount, this.ColumnCount)); } } public void SelectColumns(int col, int columns) { this.SelectRange(new RangePosition(0, col, this.rows.Count, columns)); } public void SelectRows(int row, int rows) { this.SelectRange(new RangePosition(row, 0, rows, this.cols.Count)); } private void OnTabKeyPressed(bool shiftKeyDown) { bool flag = this.selectionMode == WorksheetSelectionMode.None; if (!flag) { int num = this.focusReturnColumn; bool flag2 = !shiftKeyDown; if (flag2) { int num2 = (this.selectionRange.Cols > 1) ? this.selectionRange.EndCol : (this.cols.Count - 1); bool flag3 = this.focusPos.Col < num2; if (flag3) { this.MoveFocusRight(true); } else { int num3 = (this.selectionRange.Rows > 1) ? this.selectionRange.EndRow : (this.rows.Count - 1); bool flag4 = this.focusPos.Row < num3; if (flag4) { int col = (this.selectionRange.Cols > 1) ? this.selectionRange.Col : 0; this.focusPos.Col = col; this.MoveFocusDown(true); } } } else { int num4 = (this.selectionRange.Cols > 1) ? this.selectionRange.Col : 0; bool flag5 = this.selEnd.Col > num4; if (flag5) { this.MoveSelectionLeft(false); } else { int num5 = (this.selectionRange.Rows > 1) ? this.selectionRange.Row : 0; bool flag6 = this.selEnd.Row > num5; if (flag6) { int col2 = (this.selectionRange.Cols > 1) ? this.selectionRange.EndCol : (this.cols.Count - 1); this.focusPos.Col = col2; this.MoveSelectionUp(false); } } } this.focusReturnColumn = num; } } private void OnEnterKeyPressed(bool shiftKeyDown) { bool flag = this.selectionMode == WorksheetSelectionMode.None; if (!flag) { bool flag2 = !shiftKeyDown; if (flag2) { this.MoveSelectionForward(); } else { this.MoveSelectionBackward(); } } } public void MoveFocusRight(bool autoReturn = true) { bool flag = this.selectionMode == WorksheetSelectionMode.None; if (!flag) { this.FocusPos = this.FindNextMovableCellRight(this.focusPos, this.RangeIsMergedCell(this.selectionRange) ? this.FixRange(RangePosition.EntireRange) : this.selectionRange, autoReturn); } } public void MoveFocusDown(bool autoReturn = true) { bool flag = this.selectionMode == WorksheetSelectionMode.None; if (!flag) { this.FocusPos = this.FindNextMovableCellDown(this.focusPos, this.RangeIsMergedCell(this.selectionRange) ? this.FixRange(RangePosition.EntireRange) : this.selectionRange, autoReturn); } } private CellPosition FindNextMovableCellUp(CellPosition pos, int firstRow) { int i = pos.Row; while (i > firstRow) { i--; Cell cell = this.cells[i, pos.Col]; bool flag = cell != null && !cell.MergeEndPos.IsEmpty && i < cell.MergeEndPos.Row && i >= cell.MergeStartPos.Row; if (!flag) { bool flag2 = this.rows[i].InnerHeight > 0; if (flag2) { break; } } } return new CellPosition(i, pos.Col); } private CellPosition FindNextMovableCellLeft(CellPosition pos, int firstCol) { int i = pos.Col; while (i > firstCol) { i--; Cell cell = this.cells[pos.Row, i]; bool flag = cell != null && !cell.MergeEndPos.IsEmpty && i < cell.MergeEndPos.Col && i >= cell.MergeStartPos.Col; if (!flag) { bool flag2 = this.cols[i].InnerWidth > 0; if (flag2) { break; } } } return new CellPosition(pos.Row, i); } private CellPosition FindNextMovableCellRight(CellPosition pos, RangePosition moveRange, bool autoReturn = true) { int i = pos.Col; int num = (this.selectionRange.Cols > 1) ? this.selectionRange.EndCol : (this.cols.Count - 1); bool flag = i >= num; if (flag) { CellPosition cellPosition = this.FindNextMovableCellDown(new CellPosition(pos.Row, moveRange.Col), moveRange, false); bool flag2 = pos == cellPosition; if (flag2) { return pos; } pos = cellPosition; } int row = pos.Row; while (i < moveRange.EndCol) { i++; Cell cell = this.cells[row, i]; bool flag3 = cell != null && !cell.MergeEndPos.IsEmpty && i <= cell.MergeEndPos.Col && i > cell.MergeStartPos.Col; if (!flag3) { bool flag4 = this.cols[i].InnerWidth > 0; if (flag4) { break; } } } return new CellPosition(pos.Row, i); } private CellPosition FindNextMovableCellDown(CellPosition pos, RangePosition moveRange, bool autoReturn = true) { int i = pos.Row; while (i < moveRange.EndRow) { i++; Cell cell = this.cells[i, pos.Col]; bool flag = cell != null && !cell.MergeEndPos.IsEmpty && i <= cell.MergeEndPos.Row && i > cell.MergeStartPos.Row; if (!flag) { bool flag2 = this.rows[i].InnerHeight > 0; if (flag2) { break; } } } return new CellPosition(i, pos.Col); } public void MoveSelectionForward() { bool flag = this.SelectionMovedForward != null; if (flag) { SelectionMovedForwardEventArgs selectionMovedForwardEventArgs = new SelectionMovedForwardEventArgs(); this.SelectionMovedForward(this, selectionMovedForwardEventArgs); bool isCancelled = selectionMovedForwardEventArgs.IsCancelled; if (isCancelled) { return; } } SelectionForwardDirection selectionForwardDirection = this.selectionForwardDirection; SelectionForwardDirection selectionForwardDirection2 = selectionForwardDirection; if (selectionForwardDirection2 != SelectionForwardDirection.Right) { if (selectionForwardDirection2 == SelectionForwardDirection.Down) { bool flag2 = this.selEnd.Row < this.rows.Count - 1; if (flag2) { this.selEnd.Col = this.focusReturnColumn; this.MoveSelectionDown(false); } else { bool flag3 = this.selEnd.Col < this.cols.Count - 1; if (flag3) { this.selEnd.Row = 0; this.MoveSelectionRight(false); } } } } else { bool flag4 = this.selEnd.Col < this.cols.Count - 1; if (flag4) { this.MoveSelectionRight(false); } else { bool flag5 = this.selEnd.Row < this.rows.Count - 1; if (flag5) { this.selEnd.Col = 0; this.MoveSelectionDown(false); } } } } public void MoveSelectionBackward() { bool flag = this.SelectionMovedBackward != null; if (flag) { SelectionMovedBackwardEventArgs selectionMovedBackwardEventArgs = new SelectionMovedBackwardEventArgs(); this.SelectionMovedBackward(this, selectionMovedBackwardEventArgs); bool isCancelled = selectionMovedBackwardEventArgs.IsCancelled; if (isCancelled) { return; } } SelectionForwardDirection selectionForwardDirection = this.selectionForwardDirection; SelectionForwardDirection selectionForwardDirection2 = selectionForwardDirection; if (selectionForwardDirection2 != SelectionForwardDirection.Right) { if (selectionForwardDirection2 == SelectionForwardDirection.Down) { bool flag2 = this.selEnd.Row > 0; if (flag2) { this.MoveSelectionUp(false); } } } else { bool flag3 = this.selEnd.Col > 0; if (flag3) { this.MoveSelectionLeft(false); } } } public void MoveSelectionUp(bool appendSelect = false) { bool flag = this.selectionMode == WorksheetSelectionMode.None; if (!flag) { int i = this.selEnd.Row; while (i > 0) { i--; Cell cell = this.cells[i, this.selEnd.Col]; bool flag2 = cell != null && !cell.MergeEndPos.IsEmpty && i < cell.MergeEndPos.Row && i >= cell.MergeStartPos.Row; if (!flag2) { bool flag3 = this.rows[i].InnerHeight > 0; if (flag3) { this.MoveRangeSelection(this.selStart, new CellPosition(i, this.selEnd.Col), appendSelect, true); break; } } } } } public void MoveSelectionDown(bool appendSelect = false) { bool flag = this.selectionMode == WorksheetSelectionMode.None; if (!flag) { int i = this.selEnd.Row; while (i < this.rows.Count - 1) { i++; Cell cell = this.cells[i, this.selEnd.Col]; bool flag2 = cell != null && !cell.MergeEndPos.IsEmpty && i <= cell.MergeEndPos.Row && i > cell.MergeStartPos.Row; if (!flag2) { bool flag3 = this.rows[i].InnerHeight > 0; if (flag3) { this.MoveRangeSelection(this.selStart, new CellPosition(i, this.selEnd.Col), appendSelect, true); break; } } } } } public void MoveSelectionLeft(bool appendSelect = false) { bool flag = this.selectionMode == WorksheetSelectionMode.None; if (!flag) { int i = this.selEnd.Col; while (i > 0) { i--; Cell cell = this.cells[this.selEnd.Row, i]; bool flag2 = cell != null && !cell.MergeEndPos.IsEmpty && i < cell.MergeEndPos.Col && i >= cell.MergeStartPos.Col; if (!flag2) { bool flag3 = this.cols[i].InnerWidth > 0; if (flag3) { this.MoveRangeSelection(this.selStart, new CellPosition(this.selEnd.Row, i), appendSelect, true); break; } } } } } public void MoveSelectionRight(bool appendSelect = false) { bool flag = this.selectionMode == WorksheetSelectionMode.None; if (!flag) { int i = this.selEnd.Col; while (i < this.cols.Count - 1) { i++; Cell cell = this.cells[this.selEnd.Row, i]; bool flag2 = cell != null && !cell.MergeEndPos.IsEmpty && i <= cell.MergeEndPos.Col && i > cell.MergeStartPos.Col; if (!flag2) { bool flag3 = this.cols[i].InnerWidth > 0; if (flag3) { this.MoveRangeSelection(this.selStart, new CellPosition(this.selEnd.Row, i), appendSelect, true); break; } } } } } public void MoveSelectionHome(RowOrColumn rowOrColumn, bool appendSelect = false) { bool flag = this.selectionMode == WorksheetSelectionMode.None; if (!flag) { CellPosition cellPosition = this.selEnd; bool flag2 = (rowOrColumn & RowOrColumn.Row) == RowOrColumn.Row; if (flag2) { cellPosition.Row = 0; } bool flag3 = (rowOrColumn & RowOrColumn.Column) == RowOrColumn.Column; if (flag3) { cellPosition.Col = 0; } bool flag4 = cellPosition != this.selEnd; if (flag4) { this.MoveRangeSelection(this.selStart, cellPosition, appendSelect, true); } } } public void MoveSelectionEnd(RowOrColumn rowOrColumn, bool appendSelect = false) { bool flag = this.selectionMode == WorksheetSelectionMode.None; if (!flag) { CellPosition cellPosition = this.selEnd; bool flag2 = (rowOrColumn & RowOrColumn.Row) == RowOrColumn.Row; if (flag2) { cellPosition.Row = this.rows.Count - 1; } bool flag3 = (rowOrColumn & RowOrColumn.Column) == RowOrColumn.Column; if (flag3) { cellPosition.Col = this.cols.Count - 1; } bool flag4 = cellPosition != this.selEnd; if (flag4) { this.MoveRangeSelection(this.selStart, cellPosition, appendSelect, true); } } } public void MoveSelectionPageDown(bool appendSelect = false) { bool flag = this.selectionMode == WorksheetSelectionMode.None; if (!flag) { int num = this.selEnd.Row; NormalViewportController normalViewportController = this.viewportController as NormalViewportController; bool flag2 = normalViewportController != null; if (flag2) { IViewport viewport = normalViewportController.FocusView as IViewport; bool flag3 = viewport != null; if (flag3) { num += Math.Max(viewport.VisibleRegion.Rows - 1, 1); } } CellPosition end = this.FixPos(new CellPosition(num, this.selEnd.Col)); Cell cell = this.cells[end.Row, end.Col]; bool flag4 = cell != null; if (flag4) { cell = this.GetMergedCellOfRange(end.Row, this.selEnd.Col); end = cell.Position; } this.MoveRangeSelection(this.selStart, end, appendSelect, true); } } public void MoveSelectionPageUp(bool appendSelect = false) { bool flag = this.selectionMode == WorksheetSelectionMode.None; if (!flag) { int num = this.selEnd.Row; NormalViewportController normalViewportController = this.viewportController as NormalViewportController; bool flag2 = normalViewportController != null; if (flag2) { IViewport viewport = normalViewportController.FocusView as IViewport; bool flag3 = viewport != null; if (flag3) { num -= Math.Max(viewport.VisibleRegion.Rows - 1, 1); } } CellPosition end = this.FixPos(new CellPosition(num, this.selEnd.Col)); Cell cell = this.cells[end.Row, end.Col]; bool flag4 = cell != null; if (flag4) { cell = this.GetMergedCellOfRange(end.Row, this.selEnd.Col); end = cell.Position; } this.MoveRangeSelection(this.selStart, end, appendSelect, true); } } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler BeforeSelectionRangeChange; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler SelectionRangeChanged; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler SelectionRangeChanging; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler SelectionModeChanged; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler SelectionStyleChanged; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler SelectionForwardDirectionChanged; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler SelectionMovedForward; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler SelectionMovedBackward; public Worksheet Clone(string newName = null) { bool flag = this.workbook == null; if (flag) { throw new ReferenceObjectNotAssociatedException("worksheet must be added into workbook to do this"); } bool flag2 = string.IsNullOrEmpty(newName); if (flag2) { newName = this.workbook.GetAvailableWorksheetName(); } Worksheet worksheet = new Worksheet(this.workbook, null, 0, 0) { name = newName, RootStyle = new WorksheetRangeStyle(this.RootStyle), defaultColumnWidth = this.defaultColumnWidth, defaultRowHeight = this.defaultRowHeight, registeredNamedRanges = new Dictionary(this.registeredNamedRanges), outlines = ((this.outlines == null) ? null : new Dictionary>(this.outlines)), highlightRanges = new List(this.highlightRanges), pageBreakRows = ((this.pageBreakRows == null) ? null : new List(this.pageBreakRows)), pageBreakCols = ((this.pageBreakCols == null) ? null : new List(this.pageBreakCols)), userPageBreakCols = ((this.userPageBreakCols == null) ? null : new List(this.userPageBreakCols)), userPageBreakRows = ((this.userPageBreakRows == null) ? null : new List(this.userPageBreakRows)), settings = this.settings }; worksheet.rows.Capacity = this.rows.Count; worksheet.cols.Capacity = this.cols.Count; foreach (RowHeader rowHeader in this.rows) { worksheet.rows.Add(rowHeader.Clone(worksheet)); } foreach (ColumnHeader columnHeader in this.cols) { worksheet.cols.Add(columnHeader.Clone(worksheet)); } PartialGrid partialGrid = this.GetPartialGrid(RangePosition.EntireRange); worksheet.SetPartialGrid(RangePosition.EntireRange, partialGrid); CellPosition freezePos = this.FreezePos; bool flag3 = freezePos.Row > 0 || freezePos.Col > 0; if (flag3) { worksheet.FreezeToCell(freezePos, this.FreezeArea); } worksheet.ScaleFactor = this.ScaleFactor; worksheet.UpdateViewportController(); return worksheet; } public void Load(string file) { this.Load(file, Encoding.Default); } public void Load(string file, Encoding encoding) { bool flag = file.EndsWith(".csv", StringComparison.CurrentCultureIgnoreCase); if (flag) { this.LoadCSV(file, encoding); } else { bool flag2 = file.EndsWith(".xlsx", StringComparison.CurrentCultureIgnoreCase); if (flag2) { throw new NotSupportedException("Cannot load Excel file into single worksheet, try use Load method of control."); } bool flag3 = file.EndsWith(".xls", StringComparison.CurrentCultureIgnoreCase); if (flag3) { throw new NotSupportedException("Loading Excel 2003 format is not supported."); } this.LoadRGF(file); } string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file); bool flag4 = this.workbook == null; if (flag4) { this.name = fileNameWithoutExtension; } else { bool flag5 = !this.workbook.CheckWorksheetName(fileNameWithoutExtension); if (flag5) { this.name = this.workbook.GetAvailableWorksheetName(); } } EventHandler fileLoaded = this.FileLoaded; if (fileLoaded != null) { fileLoaded(this, new FileLoadedEventArgs(file)); } } public void LoadRGF(string path) { using (FileStream fileStream = File.OpenRead(path)) { this.LoadRGF(fileStream); } } public void LoadRGF(Stream s) { Stopwatch stopwatch = Stopwatch.StartNew(); XmlSerializer xmlSerializer = new XmlSerializer(typeof(RGXmlSheet)); RGXmlSheet rgxmlSheet; try { rgxmlSheet = (xmlSerializer.Deserialize(s) as RGXmlSheet); } catch (Exception ex) { throw new ReoGridLoadException("Read xml format error: " + ex.Message, ex); } this.Clear(); WorksheetSettings worksheetSettings = WorksheetSettings.Default; this.ScaleFactor = 1f; CultureInfo culture = Thread.CurrentThread.CurrentCulture; bool flag = rgxmlSheet.head != null; if (flag) { RGXmlHead head = rgxmlSheet.head; bool flag2 = head.settings != null; if (flag2) { RGXmlWorksheetSetting rgxmlWorksheetSetting = head.settings; bool flag3 = rgxmlWorksheetSetting.showGrid != null && !TextFormatHelper.IsSwitchOn(rgxmlWorksheetSetting.showGrid); if (flag3) { worksheetSettings = worksheetSettings.Remove(WorksheetSettings.View_ShowGridLine); } bool flag4 = TextFormatHelper.IsSwitchOn(rgxmlWorksheetSetting.showPageBreakes); if (flag4) { worksheetSettings = worksheetSettings.Add(WorksheetSettings.View_ShowPageBreaks); } else { worksheetSettings = worksheetSettings.Remove(WorksheetSettings.View_ShowPageBreaks); } bool flag5 = rgxmlWorksheetSetting.showRowHeader != null && !TextFormatHelper.IsSwitchOn(rgxmlWorksheetSetting.showRowHeader); if (flag5) { worksheetSettings = worksheetSettings.Remove(WorksheetSettings.View_ShowRowHeader); } bool flag6 = rgxmlWorksheetSetting.showColHeader != null && !TextFormatHelper.IsSwitchOn(rgxmlWorksheetSetting.showColHeader); if (flag6) { worksheetSettings = worksheetSettings.Remove(WorksheetSettings.View_ShowColumnHeader); } } string text = (head.meta == null) ? null : head.meta.culture; bool flag7 = !string.IsNullOrEmpty(text); if (flag7) { try { culture = new CultureInfo(text); } catch (Exception) { Logger.Log("load", "warning: unsupported culture: " + text); } } this.defaultRowHeight = head.defaultRowHeight; this.defaultColumnWidth = head.defaultColumnWidth; bool flag8 = head.rowHeaderWidth != null; if (flag8) { this.rowHeaderWidth = (ushort)TextFormatHelper.GetPixelValue(head.rowHeaderWidth, 40); this.userRowHeaderWidth = true; } bool flag9 = !string.IsNullOrEmpty(head.selectionMode); if (flag9) { this.selectionMode = XmlFileFormatHelper.DecodeSelectionMode(head.selectionMode); } bool flag10 = !string.IsNullOrEmpty(head.selectionStyle); if (flag10) { this.selectionStyle = XmlFileFormatHelper.DecodeSelectionStyle(head.selectionStyle); } bool flag11 = !string.IsNullOrEmpty(head.focusForwardDirection); if (flag11) { this.selectionForwardDirection = XmlFileFormatHelper.DecodeFocusForwardDirection(head.focusForwardDirection); } bool flag12 = head.printSettings != null; if (flag12) { RGXmlPrintSetting rgxmlPrintSetting = head.printSettings; bool flag13 = this.printSettings == null; if (flag13) { this.printSettings = new PrintSettings(); } int[] array = null; int[] array2 = null; bool flag14 = !string.IsNullOrEmpty(rgxmlPrintSetting.paperName); if (flag14) { this.printSettings.PaperName = rgxmlPrintSetting.paperName; } else { this.printSettings.PaperName = PaperSize.Custom.ToString(); } bool flag15 = !string.IsNullOrEmpty(rgxmlPrintSetting.paperWidth); if (flag15) { this.printSettings.PaperWidth = TextFormatHelper.GetFloatValue(rgxmlPrintSetting.paperWidth, 8.5f); } bool flag16 = !string.IsNullOrEmpty(rgxmlPrintSetting.paperHeight); if (flag16) { this.printSettings.PaperHeight = TextFormatHelper.GetFloatValue(rgxmlPrintSetting.paperHeight, 11f); } bool flag17 = TextFormatHelper.IsSwitchOn(rgxmlPrintSetting.landscape); if (flag17) { this.printSettings.Landscape = true; } bool flag18 = !string.IsNullOrEmpty(rgxmlPrintSetting.pageBreakCols); if (flag18) { array = TextFormatHelper.DecodeIntArray(rgxmlPrintSetting.pageBreakCols); } bool flag19 = !string.IsNullOrEmpty(rgxmlPrintSetting.pageBreakRows); if (flag19) { array2 = TextFormatHelper.DecodeIntArray(rgxmlPrintSetting.pageBreakRows); } float pageScaling = 1f; bool flag20 = !string.IsNullOrEmpty(rgxmlPrintSetting.scaling) && float.TryParse(rgxmlPrintSetting.scaling, out pageScaling); if (flag20) { this.PrintSettings.PageScaling = pageScaling; } bool flag21 = !string.IsNullOrEmpty(rgxmlPrintSetting.pageOrder); if (flag21) { this.PrintSettings.PageOrder = XmlFileFormatHelper.DecodePageOrder(rgxmlPrintSetting.pageOrder); } Debug.Assert(array2 == null || array2.Length >= 2); Debug.Assert(array == null || array.Length >= 2); bool flag22 = array != null && array.Length >= 2 && array2 != null && array2.Length >= 2; if (flag22) { bool flag23 = this.userPageBreakCols == null; if (flag23) { this.userPageBreakCols = new List(); } else { this.userPageBreakCols.Clear(); } bool flag24 = this.userPageBreakRows == null; if (flag24) { this.userPageBreakRows = new List(); } else { this.userPageBreakRows.Clear(); } this.userPageBreakCols.AddRange(array); this.userPageBreakRows.AddRange(array2); int num = array2[0]; int num2 = array2[array2.Length - 1]; int num3 = array[0]; int num4 = array[array.Length - 1]; this.printableRange = new RangePosition(num, num3, num2 - num, num4 - num3); bool flag25 = rgxmlPrintSetting.margins != null; if (flag25) { this.printSettings.Margins = new PageMargins((float)rgxmlPrintSetting.margins.top, (float)rgxmlPrintSetting.margins.bottom, (float)rgxmlPrintSetting.margins.left, (float)rgxmlPrintSetting.margins.right); } } } } bool flag26 = rgxmlSheet.style != null; if (flag26) { this.RootStyle = StyleUtility.ConvertFromXmlStyle(this, rgxmlSheet.style, culture); StyleUtility.CopyStyle(Worksheet.DefaultStyle, this.RootStyle, Worksheet.DefaultStyle.Flag & ~this.RootStyle.Flag); } this.Resize(rgxmlSheet.head.rows, rgxmlSheet.head.cols); foreach (RGXmlColHead rgxmlColHead in rgxmlSheet.cols) { ColumnHeader columnHeader = this.cols[rgxmlColHead.col]; bool flag27 = this.maxColumnHeader < columnHeader.Index; if (flag27) { this.maxColumnHeader = columnHeader.Index; } columnHeader.InnerWidth = rgxmlColHead.width; columnHeader.LastWidth = (ushort)TextFormatHelper.GetPixelValue(rgxmlColHead.lastWidth, 0); columnHeader.IsAutoWidth = (string.IsNullOrEmpty(rgxmlColHead.autoWidth) || TextFormatHelper.IsSwitchOn(rgxmlColHead.autoWidth)); bool flag28 = !string.IsNullOrEmpty(rgxmlColHead.text); if (flag28) { columnHeader.Text = rgxmlColHead.text; } bool flag29 = !string.IsNullOrEmpty(rgxmlColHead.textColor); if (flag29) { Color value; bool flag30 = TextFormatHelper.DecodeColor(rgxmlColHead.textColor, out value); if (flag30) { columnHeader.TextColor = new Color?(value); } } bool flag31 = rgxmlColHead.style != null; if (flag31) { columnHeader.InnerStyle = new WorksheetRangeStyle(this.RootStyle); StyleUtility.CopyStyle(StyleUtility.ConvertFromXmlStyle(this, rgxmlColHead.style, culture), this.cols[rgxmlColHead.col].InnerStyle); } bool flag32 = !string.IsNullOrEmpty(rgxmlColHead.defaultCellBody); if (flag32) { Type defaultCellBody = null; bool flag33 = CellTypesManager.CellTypes.TryGetValue(rgxmlColHead.defaultCellBody, out defaultCellBody); if (flag33) { columnHeader.DefaultCellBody = defaultCellBody; } } } foreach (RGXmlRowHead rgxmlRowHead in rgxmlSheet.rows) { RowHeader rowHeader = this.rows[rgxmlRowHead.row]; bool flag34 = this.maxRowHeader < rowHeader.Index; if (flag34) { this.maxRowHeader = rowHeader.Index; } rowHeader.InnerHeight = rgxmlRowHead.height; rowHeader.LastHeight = (ushort)TextFormatHelper.GetPixelValue(rgxmlRowHead.lastHeight, 0); rowHeader.IsAutoHeight = (string.IsNullOrEmpty(rgxmlRowHead.autoHeight) || TextFormatHelper.IsSwitchOn(rgxmlRowHead.autoHeight)); bool flag35 = !string.IsNullOrEmpty(rgxmlRowHead.text); if (flag35) { rowHeader.Text = rgxmlRowHead.text; } bool flag36 = !string.IsNullOrEmpty(rgxmlRowHead.textColor); if (flag36) { Color value2; bool flag37 = TextFormatHelper.DecodeColor(rgxmlRowHead.textColor, out value2); if (flag37) { rowHeader.TextColor = new Color?(value2); } } bool flag38 = rgxmlRowHead.style != null; if (flag38) { rowHeader.InnerStyle = new WorksheetRangeStyle(this.RootStyle); StyleUtility.CopyStyle(StyleUtility.ConvertFromXmlStyle(this, rgxmlRowHead.style, culture), this.rows[rgxmlRowHead.row].InnerStyle); } } int num5 = (int)((this.cols.Count > 0) ? this.cols[0].InnerWidth : 0); for (int i = 1; i < this.cols.Count; i++) { this.cols[i].Left = num5; num5 += (int)this.cols[i].InnerWidth; } int num6 = (int)((this.rows.Count > 0) ? this.rows[0].InnerHeight : 0); for (int j = 1; j < this.rows.Count; j++) { this.rows[j].Top = num6; num6 += (int)this.rows[j].InnerHeight; } bool flag39 = rgxmlSheet.head.outlines != null; if (flag39) { bool flag40 = rgxmlSheet.head.outlines.rowOutlines != null; if (flag40) { foreach (RGXmlOutline rgxmlOutline in rgxmlSheet.head.outlines.rowOutlines) { ReoGridOutline reoGridOutline = this.AddOutline(RowOrColumn.Row, rgxmlOutline.start, rgxmlOutline.count); bool collapsed = rgxmlOutline.collapsed; if (collapsed) { reoGridOutline.Collapse(); } } } bool flag41 = rgxmlSheet.head.outlines.colOutlines != null; if (flag41) { foreach (RGXmlOutline rgxmlOutline2 in rgxmlSheet.head.outlines.colOutlines) { ReoGridOutline reoGridOutline2 = this.AddOutline(RowOrColumn.Column, rgxmlOutline2.start, rgxmlOutline2.count); bool collapsed2 = rgxmlOutline2.collapsed; if (collapsed2) { reoGridOutline2.Collapse(); } } } } bool flag42 = rgxmlSheet.head.namedRanges != null; if (flag42) { foreach (RGXmlNamedRange rgxmlNamedRange in rgxmlSheet.head.namedRanges) { bool flag43 = RangePosition.IsValidAddress(rgxmlNamedRange.address); if (flag43) { this.AddNamedRange(new NamedRange(this, rgxmlNamedRange.name, new RangePosition(rgxmlNamedRange.address)) { Comment = rgxmlNamedRange.comment }); } } } foreach (RGXmlHBorder rgxmlHBorder in rgxmlSheet.hborder) { this.SetHBorders(rgxmlHBorder.row, rgxmlHBorder.col, rgxmlHBorder.cols, rgxmlHBorder.StyleGridBorder, XmlFileFormatHelper.DecodeHBorderOwnerPos(rgxmlHBorder.pos)); } foreach (RGXmlVBorder rgxmlVBorder in rgxmlSheet.vborder) { this.SetVBorders(rgxmlVBorder.row, rgxmlVBorder.col, rgxmlVBorder.rows, rgxmlVBorder.StyleGridBorder, XmlFileFormatHelper.DecodeVBorderOwnerPos(rgxmlVBorder.pos)); } List list = null; List list2 = null; this.suspendDataChangedEvent = true; foreach (RGXmlCell rgxmlCell in rgxmlSheet.cells) { int num7 = 1; int num8 = 1; bool flag44 = rgxmlCell.rowspan != null; if (flag44) { int.TryParse(rgxmlCell.rowspan, out num7); } bool flag45 = rgxmlCell.colspan != null; if (flag45) { int.TryParse(rgxmlCell.colspan, out num8); } Cell cell = this.CreateCell(rgxmlCell.row, rgxmlCell.col, true); bool flag46 = num7 > 1 || num8 > 1; if (flag46) { this.MergeRange(new RangePosition(rgxmlCell.row, rgxmlCell.col, num7, num8), true, false); } cell.DataFormat = XmlFileFormatHelper.DecodeCellDataFormat(rgxmlCell.dataFormat); bool flag47 = rgxmlCell.style != null; if (flag47) { WorksheetRangeStyle worksheetRangeStyle = StyleUtility.ConvertFromXmlStyle(this, rgxmlCell.style, culture); bool flag48 = worksheetRangeStyle != null; if (flag48) { this.SetCellStyle(cell, worksheetRangeStyle, StyleParentKind.Own, null); } } bool flag49 = rgxmlCell.dataFormatArgs != null && cell.DataFormat > CellDataFormatFlag.General; if (flag49) { RGXmlCellDataFormatArgs dataFormatArgs = rgxmlCell.dataFormatArgs; object obj = null; switch (cell.DataFormat) { case CellDataFormatFlag.Number: obj = new NumberDataFormatter.NumberFormatArgs { DecimalPlaces = (short)TextFormatHelper.GetFloatValue(dataFormatArgs.decimalPlaces, 2f, culture), NegativeStyle = XmlFileFormatHelper.DecodeNegativeNumberStyle(dataFormatArgs.negativeStyle), UseSeparator = TextFormatHelper.IsSwitchOn(dataFormatArgs.useSeparator) }; break; case CellDataFormatFlag.DateTime: obj = new DateTimeDataFormatter.DateTimeFormatArgs { CultureName = dataFormatArgs.culture, Format = dataFormatArgs.pattern }; break; case CellDataFormatFlag.Percent: obj = new NumberDataFormatter.NumberFormatArgs { DecimalPlaces = (short)TextFormatHelper.GetFloatValue(dataFormatArgs.decimalPlaces, 0f, culture) }; break; case CellDataFormatFlag.Currency: { string pattern = dataFormatArgs.pattern; int num9 = pattern.IndexOf(','); bool flag50 = num9 > -1; string prefixSymbol; string postfixSymbol; if (flag50) { prefixSymbol = pattern.Substring(0, num9); postfixSymbol = pattern.Substring(num9 + 1); } else { prefixSymbol = pattern; postfixSymbol = null; } obj = new CurrencyDataFormatter.CurrencyFormatArgs { DecimalPlaces = (short)TextFormatHelper.GetFloatValue(dataFormatArgs.decimalPlaces, 2f, culture), CultureEnglishName = dataFormatArgs.culture, NegativeStyle = XmlFileFormatHelper.DecodeNegativeNumberStyle(dataFormatArgs.negativeStyle), PrefixSymbol = prefixSymbol, PostfixSymbol = postfixSymbol }; break; } } bool flag51 = obj != null; if (flag51) { cell.DataFormatArgs = obj; } } string text2 = null; string text3 = null; bool flag52 = rgxmlCell.formula != null && !string.IsNullOrEmpty(rgxmlCell.formula.val); if (flag52) { text2 = rgxmlCell.formula.val; text3 = rgxmlCell.data; } else { bool flag53 = rgxmlCell.data != null && rgxmlCell.data.StartsWith("="); if (flag53) { text2 = rgxmlCell.data.Substring(1); } else { text3 = rgxmlCell.data; } } bool flag54 = !string.IsNullOrEmpty(rgxmlCell.bodyType); if (flag54) { Type type; bool flag55 = CellTypesManager.CellTypes.TryGetValue(rgxmlCell.bodyType, out type); if (flag55) { try { cell.Body = (Activator.CreateInstance(type) as ICellBody); } catch (Exception innerEx) { throw new ReoGridLoadException("Cannot create cell body instance from type: " + rgxmlCell.bodyType, innerEx); } bool flag56 = type == typeof(ImageCell); if (flag56) { int num10 = rgxmlCell.data.IndexOf(','); bool flag57 = num10 > 0; if (flag57) { string a = rgxmlCell.data.Substring(0, num10); bool flag58 = a == "image/png"; if (flag58) { string s2 = rgxmlCell.data.Substring(num10 + 1); using (MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(s2))) { ((ImageCell)cell.body).Image = Image.FromStream(memoryStream); } text3 = null; } } } } else { RGFCustomBodyHandler rgfcustomBodyHandler; bool flag59 = RGFPersistenceProvider.CustomBodyTypeHandlers.TryGetValue(rgxmlCell.bodyType, out rgfcustomBodyHandler); if (flag59) { text3 = Convert.ToString(rgfcustomBodyHandler.LoadData(cell, rgxmlCell.data)); } } } bool flag60 = !string.IsNullOrEmpty(text3); if (flag60) { this.SetSingleCellData(cell, text3); } bool flag61 = !string.IsNullOrEmpty(text2); if (flag61) { try { this.SetCellFormula(cell, text2); } catch { } } cell.IsReadOnly = TextFormatHelper.IsSwitchOn(rgxmlCell.@readonly); bool flag62 = TextFormatHelper.IsSwitchOn(rgxmlCell.tracePrecedents); if (flag62) { bool flag63 = list == null; if (flag63) { list = new List(); } list.Add(cell); } bool flag64 = TextFormatHelper.IsSwitchOn(rgxmlCell.traceDependents); if (flag64) { bool flag65 = list2 == null; if (flag65) { list2 = new List(); } list2.Add(cell); } } this.suspendDataChangedEvent = false; foreach (Cell cell2 in this.formulaRanges.Keys) { this.RecalcCell(cell2, null); } bool flag66 = list != null; if (flag66) { foreach (Cell cell3 in list) { cell3.TraceFormulaPrecedents = true; } } bool flag67 = list2 != null; if (flag67) { foreach (Cell cell4 in list2) { cell4.TraceFormulaDependents = true; } } int num11 = 0; int num12 = 0; bool flag68 = !string.IsNullOrEmpty(rgxmlSheet.head.freezeRow); if (flag68) { int.TryParse(rgxmlSheet.head.freezeRow, out num11); } bool flag69 = !string.IsNullOrEmpty(rgxmlSheet.head.freezeCol); if (flag69) { int.TryParse(rgxmlSheet.head.freezeCol, out num12); } FreezeArea area = XmlFileFormatHelper.DecodeFreezeArea(rgxmlSheet.head.freezeArea); bool flag70 = num11 > 0 || num12 > 0; if (flag70) { this.FreezeToCell(num11, num12, area); } else { this.viewDirty = true; this.UpdateViewportController(); } this.settings = worksheetSettings; EventHandler settingsChanged = this.SettingsChanged; if (settingsChanged != null) { settingsChanged(this, new SettingsChangedEventArgs { AddedSettings = this.settings }); } bool flag71 = (this.userPageBreakCols != null && this.userPageBreakCols.Count > 0) || (this.userPageBreakRows != null && this.userPageBreakRows.Count > 0); if (flag71) { this.AutoSplitPage(); } stopwatch.Stop(); Debug.WriteLine("rgf loaded: " + stopwatch.ElapsedMilliseconds.ToString() + " ms."); } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler FileLoaded; public bool Save(string path) { return this.Save(path, FileFormat._Auto); } public bool Save(string path, FileFormat format) { bool flag = format == FileFormat._Auto; if (flag) { bool flag2 = path.EndsWith(".xlsx", StringComparison.CurrentCultureIgnoreCase) || path.EndsWith(".xlsm", StringComparison.CurrentCultureIgnoreCase); if (flag2) { format = FileFormat.Excel2007; } else { bool flag3 = path.EndsWith(".xls", StringComparison.CurrentCultureIgnoreCase); if (flag3) { throw new NotSupportedException("Saving as Excel 2003 format is not supported."); } bool flag4 = path.EndsWith(".rgf", StringComparison.CurrentCultureIgnoreCase); if (flag4) { format = FileFormat.ReoGridFormat; } else { bool flag5 = path.EndsWith(".csv", StringComparison.CurrentCultureIgnoreCase); if (flag5) { format = FileFormat.CSV; } } } } FileFormat fileFormat = format; FileFormat fileFormat2 = fileFormat; bool result; if (fileFormat2 != FileFormat.ReoGridFormat) { if (fileFormat2 != FileFormat.CSV) { if (fileFormat2 != FileFormat.Excel2007) { throw new NotSupportedException("Cannot determine the saving format, try explicitly specify one."); } throw new NotSupportedException("Saving single worksheet is not supported, try use Workbook.Save instead."); } else { this.ExportAsCSV(path, 0, null); result = true; } } else { result = this.SaveRGF(path); } return result; } public bool Save(Stream stream, FileFormat format = FileFormat.ReoGridFormat) { bool result; if (format != FileFormat.ReoGridFormat) { if (format != FileFormat.CSV) { if (format != FileFormat.Excel2007) { throw new NotSupportedException(); } throw new NotImplementedException("Saving single worksheet as Excel format is not support, try use Save method from control instance."); } else { this.ExportAsCSV(stream, 0, null); result = true; } } else { result = this.SaveRGF(stream); } return result; } public bool SaveRGF(string path) { bool result; using (FileStream fileStream = new FileStream(path, FileMode.Create)) { bool flag = this.SaveRGF(fileStream); bool flag2 = flag && this.FileSaved != null; if (flag2) { this.FileSaved(this, new FileSavedEventArgs(path)); } result = flag; } return result; } public bool SaveRGF(Stream s) { string text = "ReoGrid Core"; object[] customAttributes = base.GetType().Assembly.GetCustomAttributes(typeof(AssemblyVersionAttribute), false); bool flag = customAttributes != null && customAttributes.Length != 0; if (flag) { text = text + " " + ((AssemblyVersionAttribute)customAttributes[0]).Version.ToString(); } Assembly assembly = base.GetType().Assembly; FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(assembly.Location); var rgxmlSheet = new RGXmlSheet(); var rgxmlHead = new RGXmlHead(); rgxmlHead.cols = this.cols.Count; rgxmlHead.rows = this.rows.Count; rgxmlHead.defaultColumnWidth = this.defaultColumnWidth; rgxmlHead.defaultRowHeight = this.defaultRowHeight; rgxmlHead.rowHeaderWidth = (this.userRowHeaderWidth ? this.rowHeaderWidth.ToString() : null); rgxmlHead.selectionMode = ((this.selectionMode == WorksheetSelectionMode.Range) ? null : XmlFileFormatHelper.EncodeSelectionMode(this.selectionMode)); rgxmlHead.selectionStyle = ((this.selectionStyle == WorksheetSelectionStyle.Default) ? null : XmlFileFormatHelper.EncodeSelectionStyle(this.selectionStyle)); rgxmlHead.focusForwardDirection = ((this.selectionForwardDirection == SelectionForwardDirection.Right) ? null : XmlFileFormatHelper.EncodeFocusForwardDirection(this.selectionForwardDirection)); rgxmlHead.focusCellStyle = ((this.focusPosStyle == FocusPosStyle.Default) ? null : XmlFileFormatHelper.EncodeFocusPosStyle(this.focusPosStyle)); RGXmlWorksheetSetting rgxmlWorksheetSetting = new RGXmlWorksheetSetting(); rgxmlWorksheetSetting.showGrid = TextFormatHelper.EncodeBool(this.HasSettings(WorksheetSettings.View_ShowGridLine), WorksheetSettings.Default.Has(WorksheetSettings.View_ShowGridLine)); rgxmlWorksheetSetting.showPageBreakes = TextFormatHelper.EncodeBool(this.HasSettings(WorksheetSettings.View_ShowPageBreaks), WorksheetSettings.Default.Has(WorksheetSettings.View_ShowPageBreaks)); rgxmlWorksheetSetting.showRowHeader = TextFormatHelper.EncodeBool(this.HasSettings(WorksheetSettings.View_ShowRowHeader), WorksheetSettings.Default.Has(WorksheetSettings.View_ShowRowHeader)); rgxmlWorksheetSetting.showColHeader = TextFormatHelper.EncodeBool(this.HasSettings(WorksheetSettings.View_ShowColumnHeader), WorksheetSettings.Default.Has(WorksheetSettings.View_ShowColumnHeader)); rgxmlWorksheetSetting.@readonly = TextFormatHelper.EncodeBool(this.HasSettings(WorksheetSettings.Edit_Readonly), WorksheetSettings.Default.Has(WorksheetSettings.Edit_Readonly)); rgxmlWorksheetSetting.allowAdjustRowHeight = TextFormatHelper.EncodeBool(this.HasSettings(WorksheetSettings.Edit_AllowAdjustRowHeight), WorksheetSettings.Default.Has(WorksheetSettings.Edit_AllowAdjustRowHeight)); rgxmlWorksheetSetting.allowAdjustColumnWidth = TextFormatHelper.EncodeBool(this.HasSettings(WorksheetSettings.Edit_AllowAdjustColumnWidth), WorksheetSettings.Default.Has(WorksheetSettings.Edit_AllowAdjustColumnWidth)); long num = (long)this.settings; rgxmlWorksheetSetting.metaValue = num.ToString(); rgxmlHead.settings = rgxmlWorksheetSetting; rgxmlHead.meta = new RGXmlMeta { culture = Thread.CurrentThread.CurrentCulture.Name, editor = text, controlVersion = versionInfo.FileVersion }; rgxmlSheet.head = rgxmlHead; rgxmlSheet.style = StyleUtility.ConvertToXmlStyle(this.RootStyle); RGXmlHead head = rgxmlSheet.head; bool flag2 = this.printSettings != null && (this.pageBreakRows != null && this.pageBreakCols != null && this.pageBreakRows.Count > 1) && this.pageBreakCols.Count > 1; if (flag2) { RGXmlPrintSetting rgxmlPrintSetting = head.printSettings = new RGXmlPrintSetting(); bool flag3 = this.userPageBreakRows != null && this.userPageBreakRows.Count > 0; if (flag3) { rgxmlPrintSetting.pageBreakRows = TextFormatHelper.EncodeIntArray(this.userPageBreakRows); } bool flag4 = this.userPageBreakCols != null && this.userPageBreakCols.Count > 0; if (flag4) { rgxmlPrintSetting.pageBreakCols = TextFormatHelper.EncodeIntArray(this.userPageBreakCols); } bool flag5 = this.printSettings != null; if (flag5) { rgxmlPrintSetting.paperName = this.printSettings.PaperName; rgxmlPrintSetting.pageOrder = XmlFileFormatHelper.EncodePageOrder(this.printSettings.PageOrder); rgxmlPrintSetting.scaling = this.printSettings.PageScaling.ToString(); rgxmlPrintSetting.landscape = TextFormatHelper.EncodeBool(this.printSettings.Landscape); rgxmlPrintSetting.paperWidth = this.printSettings.PaperWidth.ToString(); rgxmlPrintSetting.paperHeight = this.printSettings.PaperHeight.ToString(); PageMargins margins = this.printSettings.Margins; rgxmlPrintSetting.margins = new RGXmlMargins { left = (double)margins.Left, right = (double)margins.Right, top = (double)margins.Top, bottom = (double)margins.Bottom }; } } CellPosition freezePos = this.FreezePos; bool flag6 = freezePos.Row > 0 || freezePos.Col > 0; if (flag6) { head.freezeRow = freezePos.Row.ToString(); head.freezeCol = freezePos.Col.ToString(); head.freezeArea = XmlFileFormatHelper.EncodeFreezeArea(this.FreezeArea); } bool flag7 = this.outlines != null; if (flag7) { Action, List> action = delegate(OutlineCollection outlines, List xmlOutlines) { outlines.IterateOutlines(delegate(ReoGridOutline outline) { xmlOutlines.Add(new RGXmlOutline { start = outline.Start, count = outline.Count, collapsed = outline.InternalCollapsed }); return true; }); }; OutlineCollection outlineCollection = this.GetOutlines(RowOrColumn.Row); bool flag8 = outlineCollection != null; if (flag8) { bool flag9 = head.outlines == null; if (flag9) { head.outlines = new RGXmlOutlineList(); } head.outlines.rowOutlines = new List(); action(outlineCollection, head.outlines.rowOutlines); } OutlineCollection outlineCollection2 = this.GetOutlines(RowOrColumn.Column); bool flag10 = outlineCollection2 != null; if (flag10) { bool flag11 = head.outlines == null; if (flag11) { head.outlines = new RGXmlOutlineList(); } head.outlines.colOutlines = new List(); action(outlineCollection2, head.outlines.colOutlines); } } bool flag12 = this.registeredNamedRanges.Count > 0; if (flag12) { head.namedRanges = new List(); head.namedRanges.AddRange(from nr in this.registeredNamedRanges.Values select new RGXmlNamedRange { name = nr.Name, comment = nr.Comment, address = nr.Position.ToAddress() }); } int maxContentRow = this.MaxContentRow; int maxContentCol = this.MaxContentCol; foreach (RowHeader rowHeader in this.rows) { bool flag13 = rowHeader.InnerHeight != this.defaultRowHeight || rowHeader.InnerStyle != null || !rowHeader.IsAutoHeight || rowHeader.LastHeight != 0 || !string.IsNullOrEmpty(rowHeader.Text) || rowHeader.TextColor != null; WorksheetRangeStyle worksheetRangeStyle = StyleUtility.DistinctStyle(rowHeader.InnerStyle, this.RootStyle); bool flag14 = flag13 || worksheetRangeStyle != null; if (flag14) { rgxmlSheet.rows.Add(new RGXmlRowHead { row = rowHeader.Row, height = rowHeader.InnerHeight, lastHeight = ((rowHeader.LastHeight == 0) ? null : rowHeader.LastHeight.ToString()), autoHeight = (rowHeader.IsAutoHeight ? null : TextFormatHelper.EncodeBool(rowHeader.IsAutoHeight)), text = (string.IsNullOrEmpty(rowHeader.Text) ? null : rowHeader.Text), textColor = ((rowHeader.TextColor == null) ? null : TextFormatHelper.EncodeColor(rowHeader.TextColor.Value)), style = StyleUtility.ConvertToXmlStyle(worksheetRangeStyle) }); } } foreach (ColumnHeader columnHeader in this.cols) { bool flag15 = columnHeader.InnerWidth != this.defaultColumnWidth || columnHeader.InnerStyle != null || !columnHeader.IsAutoWidth || columnHeader.LastWidth != 0 || !string.IsNullOrEmpty(columnHeader.Text) || columnHeader.TextColor != null || columnHeader.DefaultCellBody != null; WorksheetRangeStyle worksheetRangeStyle2 = StyleUtility.DistinctStyle(columnHeader.InnerStyle, this.RootStyle); bool flag16 = flag15 || worksheetRangeStyle2 != null; if (flag16) { rgxmlSheet.cols.Add(new RGXmlColHead { col = columnHeader.Col, width = columnHeader.InnerWidth, lastWidth = ((columnHeader.LastWidth == 0) ? null : columnHeader.LastWidth.ToString()), autoWidth = (columnHeader.IsAutoWidth ? null : TextFormatHelper.EncodeBool(columnHeader.IsAutoWidth)), text = (string.IsNullOrEmpty(columnHeader.Text) ? null : columnHeader.Text), textColor = ((columnHeader.TextColor == null) ? null : TextFormatHelper.EncodeColor(columnHeader.TextColor.Value)), style = StyleUtility.ConvertToXmlStyle(worksheetRangeStyle2), defaultCellBody = ((columnHeader.DefaultCellBody == null) ? null : columnHeader.DefaultCellBody.FullName) }); } } for (int i = 0; i <= maxContentRow + 1; i++) { int j = 0; while (j <= maxContentCol) { ReoGridHBorder reoGridHBorder = this.hBorders[i, j]; bool flag17 = reoGridHBorder != null && reoGridHBorder.Span > 0 && reoGridHBorder.Style != null && reoGridHBorder.Style.Style > BorderLineStyle.None; if (flag17) { rgxmlSheet.hborder.Add(new RGXmlHBorder(i, j, reoGridHBorder.Span, reoGridHBorder.Style, reoGridHBorder.Pos)); j += reoGridHBorder.Span; } else { j++; } } } for (int k = 0; k <= maxContentCol + 1; k++) { int l = 0; while (l <= maxContentRow) { ReoGridVBorder reoGridVBorder = this.vBorders[l, k]; bool flag18 = reoGridVBorder != null && reoGridVBorder.Span > 0 && reoGridVBorder.Style != null && reoGridVBorder.Style.Style > BorderLineStyle.None; if (flag18) { rgxmlSheet.vborder.Add(new RGXmlVBorder(l, k, reoGridVBorder.Span, reoGridVBorder.Style, reoGridVBorder.Pos)); l += reoGridVBorder.Span; } else { l++; } } } this.cells.Iterate(0, 0, maxContentRow + 1, maxContentCol + 1, true, delegate(int r, int c, Cell cell) { bool flag19 = cell.IsValidCell || cell.IsStartMergedCell; if (flag19) { bool flag20 = false; bool flag21 = cell.InnerData != null || cell.Rowspan > 1 || cell.Colspan > 1 || cell.body != null; if (flag21) { flag20 = true; } RGXmlCellStyle rgxmlCellStyle = null; bool flag22 = cell.StyleParentKind == StyleParentKind.Own; if (flag22) { rgxmlCellStyle = StyleUtility.ConvertToXmlStyle(StyleUtility.CheckAndRemoveCellStyle(this, cell)); bool flag23 = rgxmlCellStyle != null; if (flag23) { flag20 = true; } } RGXmlCellDataFormatArgs rgxmlCellDataFormatArgs = null; bool flag24 = cell.DataFormat > CellDataFormatFlag.General; if (flag24) { flag20 = true; switch (cell.DataFormat) { case CellDataFormatFlag.Number: { NumberDataFormatter.NumberFormatArgs numberFormatArgs = (NumberDataFormatter.NumberFormatArgs)cell.DataFormatArgs; rgxmlCellDataFormatArgs = new RGXmlCellDataFormatArgs(); rgxmlCellDataFormatArgs.decimalPlaces = numberFormatArgs.DecimalPlaces.ToString(); rgxmlCellDataFormatArgs.negativeStyle = XmlFileFormatHelper.EncodeNegativeNumberStyle(numberFormatArgs.NegativeStyle); rgxmlCellDataFormatArgs.useSeparator = TextFormatHelper.EncodeBool(numberFormatArgs.UseSeparator); break; } case CellDataFormatFlag.DateTime: { DateTimeDataFormatter.DateTimeFormatArgs dateTimeFormatArgs = (DateTimeDataFormatter.DateTimeFormatArgs)cell.DataFormatArgs; rgxmlCellDataFormatArgs = new RGXmlCellDataFormatArgs(); rgxmlCellDataFormatArgs.culture = dateTimeFormatArgs.CultureName; rgxmlCellDataFormatArgs.pattern = dateTimeFormatArgs.Format; break; } case CellDataFormatFlag.Percent: { NumberDataFormatter.NumberFormatArgs numberFormatArgs2 = (NumberDataFormatter.NumberFormatArgs)cell.DataFormatArgs; rgxmlCellDataFormatArgs = new RGXmlCellDataFormatArgs(); rgxmlCellDataFormatArgs.decimalPlaces = numberFormatArgs2.DecimalPlaces.ToString(); break; } case CellDataFormatFlag.Currency: { CurrencyDataFormatter.CurrencyFormatArgs currencyFormatArgs = (CurrencyDataFormatter.CurrencyFormatArgs)cell.DataFormatArgs; rgxmlCellDataFormatArgs = new RGXmlCellDataFormatArgs(); rgxmlCellDataFormatArgs.decimalPlaces = currencyFormatArgs.DecimalPlaces.ToString(); rgxmlCellDataFormatArgs.culture = currencyFormatArgs.CultureEnglishName; rgxmlCellDataFormatArgs.negativeStyle = XmlFileFormatHelper.EncodeNegativeNumberStyle(currencyFormatArgs.NegativeStyle); rgxmlCellDataFormatArgs.pattern = currencyFormatArgs.PrefixSymbol + "," + currencyFormatArgs.PostfixSymbol; break; } } } bool flag25 = flag20; if (flag25) { RGXmlCell rgxmlCell = new RGXmlCell { row = r, col = c, colspan = ((cell.Colspan == 1) ? null : cell.Colspan.ToString()), rowspan = ((cell.Rowspan == 1) ? null : cell.Rowspan.ToString()), style = rgxmlCellStyle, dataFormat = XmlFileFormatHelper.EncodeCellDataFormat(cell.DataFormat), dataFormatArgs = ((rgxmlCellDataFormatArgs == null || rgxmlCellDataFormatArgs.IsEmpty) ? null : rgxmlCellDataFormatArgs), @readonly = ((!cell.IsReadOnly) ? null : TextFormatHelper.EncodeBool(cell.IsReadOnly)), bodyType = ((cell.body == null) ? null : cell.body.GetType().Name), tracePrecedents = (cell.TraceFormulaPrecedents ? TextFormatHelper.EncodeBool(cell.TraceFormulaPrecedents) : null), traceDependents = (cell.TraceFormulaDependents ? TextFormatHelper.EncodeBool(cell.TraceFormulaDependents) : null) }; bool flag26 = cell.HasFormula || !(cell.InnerData is bool); if (flag26) { rgxmlCell.data = Convert.ToString(cell.InnerData); RGXmlCell rgxmlCell2 = rgxmlCell; object formula; if (!cell.HasFormula) { formula = null; } else { ((RGXmlCellFormual)(formula = new RGXmlCellFormual())).val = cell.InnerFormula; } rgxmlCell2.formula = (RGXmlCellFormual)formula; } else { bool flag27 = cell.InnerData is bool; if (flag27) { rgxmlCell.formula = new RGXmlCellFormual { val = (((bool)cell.InnerData) ? "True" : "False") }; } } bool flag28 = cell.body != null; if (flag28) { bool flag29 = cell.body is ImageCell; if (flag29) { ImageCell imageCell = (ImageCell)cell.body; using (MemoryStream memoryStream = new MemoryStream(4096)) { Image image = ((ImageCell)cell.body).Image; image.SaveToStream(ImageFormat.Png, memoryStream); rgxmlCell.data = "image/png," + Convert.ToBase64String(memoryStream.ToArray()); } } else { string text2; bool flag30 = RGFPersistenceProvider.CustomBodyTypeIdentifiers.TryGetValue(cell.body.GetType(), out text2); if (flag30) { RGFCustomBodyHandler rgfcustomBodyHandler; bool flag31 = RGFPersistenceProvider.CustomBodyTypeHandlers.TryGetValue(text2, out rgfcustomBodyHandler); if (flag31) { rgxmlCell.bodyType = text2; rgxmlCell.data = rgfcustomBodyHandler.SaveData(cell); } } } } rgxmlSheet.cells.Add(rgxmlCell); } } return 1; }); XmlSerializer xmlSerializer = new XmlSerializer(typeof(RGXmlSheet)); xmlSerializer.Serialize(s, rgxmlSheet); return true; } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler FileSaved; internal void InitViewportController() { this.viewportController = new NormalViewportController(this); } internal IControlAdapter ControlAdapter { get { return this.controlAdapter; } set { this.controlAdapter = value; bool flag = this.controlAdapter == null; if (flag) { this.viewportController = null; } else { bool flag2 = this.viewportController == null; if (flag2) { this.InitViewportController(); } } } } public IWorkbook Workbook { get { return this.workbook; } } private void CheckWorkbookAssociated() { bool flag = this.workbook == null; if (flag) { throw new InvalidOperationException("Worksheet is not associated to any workbook. Add it into workbook firstly."); } } public string Name { get { return this.name; } set { bool flag = string.IsNullOrEmpty(value); if (flag) { throw new ArgumentNullException("cannot set worksheet's name to null or empty."); } bool flag2 = this.name == value; if (!flag2) { bool flag3 = this.workbook != null; if (flag3) { this.workbook.ValidateWorksheetName(value); value = this.workbook.NotifyWorksheetNameChange(this, value); } this.name = value; bool flag4 = this.NameChanged != null; if (flag4) { this.NameChanged(this, null); } bool flag5 = this.workbook != null; if (flag5) { this.workbook.RaiseWorksheetNameChangedEvent(this); } } } } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler NameChanged; public Color NameBackColor { get { return this.nameBackColor; } set { this.nameBackColor = value; this.OnNameBackColorChanged(); } } public Color NameTextColor { get { return this.nameTextColor; } set { this.nameTextColor = value; this.OnNameTextColorChanged(); } } internal void OnNameBackColorChanged() { bool flag = this.workbook != null; if (flag) { this.workbook.RaiseWorksheetNameBackColorChangedEvent(this); } } internal void OnNameTextColorChanged() { bool flag = this.workbook != null; if (flag) { this.workbook.RaiseWorksheetNameTextColorChangedEvent(this); } } internal Worksheet(Workbook workbook, string name) : this(workbook, name, 200, 100) { } internal Worksheet(Workbook workbook, string name, int rows, int cols) { float num = -1f; float num2 = -1f; this.lastMouseMoving = new Point(ref num, ref num2); this.lastChangedSelectionRange = RangePosition.Empty; this.draggingSelectionRange = RangePosition.Empty; this.focusMovingRangeOffset = CellPosition.Empty; this.waitingEndDirection = false; this.indentSize = 8f; this.workbook = workbook; this.name = name; this.ControlAdapter = workbook.controlAdapter; this.InitGrid(rows, cols); } public FreezeArea FreezeArea { get; private set; } public CellPosition FreezePos { get; private set; } public void FreezeToCell(CellPosition pos) { this.FreezeToCell(pos.Row, pos.Col); } public void FreezeToCell(string address) { bool flag = CellPosition.IsValidAddress(address); if (flag) { this.FreezeToCell(new CellPosition(address)); } else { RangePosition rangePosition; bool flag2 = this.TryGetNamedRangePosition(address, out rangePosition); if (!flag2) { throw new InvalidAddressException(address); } this.FreezeToCell(rangePosition.StartPos); } } public void FreezeToCell(CellPosition pos, FreezeArea area) { this.FreezeToCell(pos.Row, pos.Col, area); } public void FreezeToCell(int row, int col) { bool flag = row < 0 || col < 0 || row >= this.rows.Count || col >= this.cols.Count; if (!flag) { this.FreezeToCell(row, col, FreezeArea.LeftTop); } } public void FreezeToCell(int row, int col, FreezeArea area) { bool flag = this.viewportController != null; if (flag) { this.viewportController.Bounds = this.controlAdapter.GetContainerBounds(); } bool flag2 = this.viewportController is IFreezableViewportController; if (flag2) { bool flag3 = area == FreezeArea.None; if (flag3) { row = 0; col = 0; } else { bool flag4 = area == FreezeArea.Left; if (flag4) { row = 0; area = FreezeArea.LeftTop; } else { bool flag5 = area == FreezeArea.Right; if (flag5) { row = 0; area = FreezeArea.RightTop; } else { bool flag6 = area == FreezeArea.Top; if (flag6) { col = 0; area = FreezeArea.LeftTop; } else { bool flag7 = area == FreezeArea.Bottom; if (flag7) { col = 0; area = FreezeArea.LeftBottom; } } } } } } this.FreezePos = new CellPosition(row, col); this.FreezeArea = area; IFreezableViewportController freezableViewportController = this.viewportController as IFreezableViewportController; bool flag8 = freezableViewportController != null; if (flag8) { freezableViewportController.Freeze(this.FreezePos, area); this.RequestInvalidate(); bool flag9 = row > 0 || col > 0; if (flag9) { EventHandler cellsFrozen = this.CellsFrozen; if (cellsFrozen != null) { cellsFrozen(this, null); } } else { EventHandler cellsUnfrozen = this.CellsUnfrozen; if (cellsUnfrozen != null) { cellsUnfrozen(this, null); } } } } public void Unfreeze() { this.FreezeToCell(0, 0); } public bool CanFreeze() { return this.viewportController is IFreezableViewportController; } public bool IsFrozen { get { return (this.FreezePos.Row > 0 || this.FreezePos.Col > 0) && this.FreezeArea > FreezeArea.None; } } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler CellsFrozen; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler CellsUnfrozen; public float ScaleFactor { get { return this._scaleFactor; } set { this.SetScale(value); } } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler Scaled; public void SetScale(float factor) { bool flag = this.currentEditingCell != null; if (flag) { this.EndEdit(EndEditReason.NormalFinish); } bool flag2 = this.controlAdapter == null; if (flag2) { bool flag3 = factor < Worksheet.minScaleFactor; if (flag3) { factor = Worksheet.minScaleFactor; } bool flag4 = factor > Worksheet.maxScaleFactor; if (flag4) { factor = Worksheet.maxScaleFactor; } } else { bool flag5 = factor < this.controlAdapter.MinScale; if (flag5) { factor = this.controlAdapter.MinScale; } bool flag6 = factor > this.controlAdapter.MaxScale; if (flag6) { factor = this.controlAdapter.MaxScale; } } bool flag7 = this._scaleFactor != factor; if (flag7) { this._scaleFactor = factor; bool flag8 = this.controlAdapter == null; if (flag8) { this.renderScaleFactor = this._scaleFactor; } else { this.renderScaleFactor = this.controlAdapter.BaseScale + this._scaleFactor; } IScalableViewportController scalableViewportController = this.viewportController as IScalableViewportController; bool flag9 = scalableViewportController != null; if (flag9) { scalableViewportController.ScaleFactor = this.renderScaleFactor; } IViewportController viewportController = this.viewportController; if (viewportController != null) { viewportController.UpdateController(); } EventHandler scaled = this.Scaled; if (scaled != null) { scaled(this, null); } } } public void ZoomIn() { this.SetScale(this._scaleFactor + 0.1f); } public void ZoomOut() { this.SetScale(this._scaleFactor - 0.1f); } public void ZoomReset() { this.SetScale(1f); } public object this[CellPosition pos] { get { return this[pos.Row, pos.Col]; } set { this[pos.Row, pos.Col] = value; } } public object this[int row, int col] { get { Cell cell = this.GetCell(row, col); return (cell == null) ? null : cell.InnerData; } set { this.SetCellData(row, col, value); } } public object this[int row, int col, int rows, int cols] { get { return this[new RangePosition(row, col, rows, cols)]; } set { this[new RangePosition(row, col, rows, cols)] = value; } } public object this[RangePosition range] { get { return this.GetRangeData(range); } set { this.SetRangeData(range, value); } } public object this[string addressOrName] { get { bool flag = CellPosition.IsValidAddress(addressOrName); object result; if (flag) { result = this[new CellPosition(addressOrName)]; } else { bool flag2 = RangePosition.IsValidAddress(addressOrName); if (flag2) { result = this[new RangePosition(addressOrName)]; } else { NamedRange refRange; bool flag3 = this.registeredNamedRanges.TryGetValue(addressOrName, out refRange); if (!flag3) { throw new InvalidAddressException(addressOrName); } result = this[refRange]; } } return result; } set { bool flag = CellPosition.IsValidAddress(addressOrName); if (flag) { this[new CellPosition(addressOrName)] = value; } else { bool flag2 = RangePosition.IsValidAddress(addressOrName); if (flag2) { this[new RangePosition(addressOrName)] = value; } else { NamedRange refRange; bool flag3 = this.registeredNamedRanges.TryGetValue(addressOrName, out refRange); if (!flag3) { throw new InvalidAddressException(addressOrName); } this[refRange] = value; } } } } internal object this[Cell cell] { get { return cell.InnerData; } set { this.SetSingleCellData(cell, value); } } public Cell CreateAndGetCell(string address) { return CellPosition.IsValidAddress(address) ? this.CreateAndGetCell(new CellPosition(address)) : null; } public Cell CreateAndGetCell(CellPosition pos) { return this.CreateAndGetCell(pos.Row, pos.Col); } public Cell CreateAndGetCell(int row, int col) { Cell cell = this.cells[row, col]; bool flag = cell == null; if (flag) { cell = this.CreateCell(row, col, true); } return cell; } internal Cell CreateCell(int row, int col, bool updateStyle = true) { Cell cell = new Cell(this) { InternalRow = row, InternalCol = col, Colspan = 1, Rowspan = 1, Bounds = this.GetCellRectFromHeader(row, col) }; StyleUtility.UpdateCellParentStyle(this, cell); this.cells[row, col] = cell; ColumnHeader columnHeader = this.cols[col]; RowHeader rowHeader = this.rows[row]; bool flag = columnHeader.DefaultCellBody != null; if (flag) { try { cell.Body = (Activator.CreateInstance(columnHeader.DefaultCellBody) as ICellBody); } catch (Exception inner) { throw new CannotCreateCellBodyException("Cannot create instance of default cell body specified in column header.", inner); } } else { bool flag2 = rowHeader.DefaultCellBody != null; if (flag2) { try { cell.Body = (Activator.CreateInstance(rowHeader.DefaultCellBody) as ICellBody); } catch (Exception inner2) { throw new CannotCreateCellBodyException("Cannot create instance of default cell body specified in row header.", inner2); } } } bool flag3 = cell.body != null; if (flag3) { cell.body.OnSetup(cell); } if (updateStyle) { StyleUtility.UpdateCellRenderAlign(this, cell); this.UpdateCellFont(cell, UpdateFontReason.FontChanged); } return cell; } public Cell GetCell(string addressOrName) { bool flag = CellPosition.IsValidAddress(addressOrName); Cell cell; if (flag) { cell = this.GetCell(new CellPosition(addressOrName)); } else { NamedRange namedRange; bool flag2 = this.registeredNamedRanges.TryGetValue(addressOrName, out namedRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } cell = this.GetCell(namedRange.StartPos); } return cell; } public Cell GetCell(CellPosition pos) { return this.GetCell(pos.Row, pos.Col); } public Cell GetCell(int row, int col) { return this.cells[row, col]; } public Cell GetMergedCellOfRange(string address) { return CellPosition.IsValidAddress(address) ? this.GetMergedCellOfRange(new CellPosition(address)) : null; } public Cell GetMergedCellOfRange(CellPosition pos) { return this.GetMergedCellOfRange(pos.Row, pos.Col); } public Cell GetMergedCellOfRange(int row, int col) { return this.GetMergedCellOfRange(this.CreateAndGetCell(row, col)); } public Cell GetMergedCellOfRange(Cell cell) { bool flag = cell == null; Cell result; if (flag) { result = null; } else { bool insideMergedRange = cell.InsideMergedRange; if (insideMergedRange) { bool isStartMergedCell = cell.IsStartMergedCell; if (isStartMergedCell) { result = cell; } else { result = this.CreateAndGetCell(cell.MergeStartPos); } } else { result = cell; } } return result; } public RangePosition GetRangeIfMergedCell(CellPosition pos) { Cell cell = this.cells[pos.Row, pos.Col]; bool flag = cell == null; RangePosition result; if (flag) { result = new RangePosition(pos, pos); } else { bool isStartMergedCell = cell.IsStartMergedCell; if (isStartMergedCell) { result = new RangePosition(cell.Row, cell.Column, (int)cell.Rowspan, (int)cell.Colspan); } else { bool flag2 = !cell.IsValidCell; if (flag2) { result = this.GetRangeIfMergedCell(cell.MergeStartPos); } else { result = new RangePosition(pos, pos); } } } return result; } public bool IsMergedCell(string address) { return CellPosition.IsValidAddress(address) && this.IsMergedCell(new CellPosition(address)); } public bool IsMergedCell(CellPosition pos) { return this.IsMergedCell(pos.Row, pos.Col); } public bool IsMergedCell(RangePosition range) { Cell cell = this.GetCell(range.StartPos); bool flag = cell == null; bool result; if (flag) { result = (range.Rows == 1 && range.Cols == 1); } else { result = ((int)cell.Rowspan == range.Rows && (int)cell.Colspan == range.Cols); } return result; } public bool IsMergedCell(int row, int col) { Cell cell = this.cells[row, col]; return cell != null && cell.IsMergedCell; } public bool IsValidCell(string address) { return CellPosition.IsValidAddress(address) && this.IsValidCell(new CellPosition(address)); } public bool IsValidCell(CellPosition pos) { return this.IsValidCell(pos.Row, pos.Col); } public bool IsValidCell(int row, int col) { bool flag = row < 0 || col < 0 || row >= this.cells.RowCapacity || col >= this.cells.ColCapacity; bool result; if (flag) { result = false; } else { Cell cell = this.cells[row, col]; result = (cell == null || cell.IsValidCell); } return result; } public bool IsCellVisible(Cell cell) { return this.IsCellVisible(cell.InternalPos); } public bool IsCellVisible(CellPosition pos) { return this.IsCellVisible(pos.Row, pos.Col); } public bool IsCellVisible(int row, int col) { return this.IsRowVisible(row) && this.IsColumnVisible(col); } public void IterateCells(string addressOrName, Func iterator) { this.IterateCells(addressOrName, true, iterator); } public void IterateCells(string addressOrName, bool skipEmptyCells, Func iterator) { bool flag = RangePosition.IsValidAddress(addressOrName); if (flag) { this.IterateCells(new RangePosition(addressOrName), skipEmptyCells, iterator); } else { NamedRange refRange; bool flag2 = this.registeredNamedRanges.TryGetValue(addressOrName, out refRange); if (!flag2) { throw new InvalidAddressException(addressOrName); } this.IterateCells(refRange, skipEmptyCells, iterator); } } public void IterateCells(RangePosition range, Func iterator) { this.IterateCells(range, true, iterator); } public void IterateCells(RangePosition range, bool skipEmptyCells, Func iterator) { RangePosition rangePosition = this.FixRange(range); this.IterateCells(rangePosition.Row, rangePosition.Col, rangePosition.Rows, rangePosition.Cols, skipEmptyCells, iterator); } public void IterateCells(int row, int col, int rows, int cols, bool skipEmptyCells, Func iterator) { this.cells.Iterate(row, col, rows, cols, skipEmptyCells, delegate(int r, int c, Cell cell) { int num = (int)((cell == null) ? 1 : cell.Colspan); bool flag = num <= 0; int result; if (flag) { result = 1; } else { bool flag2 = !iterator(r, c, cell); if (flag2) { result = 0; } else { result = ((num <= 0) ? 1 : num); } } return result; }); } public RangePosition UsedRange { get { return RangePosition.FromCellPosition(0, 0, this.MaxContentRow, this.MaxContentCol); } } public int MaxContentRow { get { return Math.Min(this.rows.Count - 1, Math.Max(Math.Max(this.cells.MaxRow, Math.Max(this.hBorders.MaxRow - 1, this.vBorders.MaxRow)), this.maxRowHeader + 1)); } } public int MaxContentCol { get { return Math.Min(this.cols.Count - 1, Math.Max(Math.Max(this.cells.MaxCol, Math.Max(this.hBorders.MaxCol, this.vBorders.MaxCol - 1)), this.maxColumnHeader + 1)); } } public Worksheet.CellCollection Cells { get { bool flag = this.cellCollection == null; if (flag) { this.cellCollection = new Worksheet.CellCollection(this); } return this.cellCollection; } } internal void OnMouseWheel(Point location, int delta, MouseButtons buttons, InputModifiers modifiers) { this.waitingEndDirection = false; bool flag = modifiers.HasFlag(InputModifiers.Control); if (flag) { bool flag2 = this.HasSettings(WorksheetSettings.Behavior_MouseWheelToZoom); if (flag2) { this.SetScale(this.ScaleFactor + 0.001f * (float)delta); } } else { bool flag3 = !this.selStart.IsEmpty; if (flag3) { Cell cell = this.cells[this.selStart.Row, this.selStart.Col]; float num = this.renderScaleFactor; Rect cellBounds = this.GetCellBounds(this.selStart); cellBounds.X *= num; cellBounds.Y *= num; cellBounds.Width *= num; cellBounds.Height *= num; float num2 = location.X - cellBounds.X; float num3 = location.Y - cellBounds.Y; Point relativePosition = new Point(ref num2, ref num3); CellMouseEventArgs e = new CellMouseEventArgs(this, cell, this.selStart, relativePosition, location, buttons, 0) { Delta = delta, CellPosition = this.selStart }; bool flag4 = cell != null && cell.body != null; if (flag4) { cell.body.OnMouseWheel(e); } } bool flag5 = this.controlAdapter != null && this.HasSettings(WorksheetSettings.Behavior_MouseWheelToScroll); if (flag5) { IScrollableViewportController scrollableViewportController = this.viewportController as IScrollableViewportController; bool flag6 = scrollableViewportController != null; if (flag6) { bool flag7 = modifiers.HasFlag(InputModifiers.Shift); if (flag7) { scrollableViewportController.ScrollOffsetViews(ScrollDirection.Horizontal, (float)(-(float)delta), 0f); } else { scrollableViewportController.ScrollOffsetViews(ScrollDirection.Vertical, 0f, (float)(-(float)delta)); } } } } } internal bool IgnoreMouseDoubleClick { get; set; } internal void OnMouseDoubleClick(Point location, MouseButtons buttons) { bool flag = this.viewportController != null && !this.IgnoreMouseDoubleClick && this.selectionMode > WorksheetSelectionMode.None; if (flag) { this.viewportController.OnMouseDoubleClick(location, buttons); } this.IgnoreMouseDoubleClick = false; } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler CellMouseEnter; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler CellMouseLeave; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler CellMouseMove; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler CellMouseDown; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler CellMouseUp; internal bool HasCellMouseDown { get { return this.CellMouseDown != null; } } internal void RaiseCellMouseDown(CellMouseEventArgs args) { bool flag = this.CellMouseDown != null; if (flag) { this.CellMouseDown(this, args); } } internal bool HasCellMouseUp { get { return this.CellMouseUp != null; } } internal void RaiseCellMouseUp(CellMouseEventArgs args) { bool flag = this.CellMouseUp != null; if (flag) { this.CellMouseUp(this, args); } } internal bool HasCellMouseMove { get { return this.CellMouseMove != null; } } internal void RaiseCellMouseMove(CellMouseEventArgs args) { bool flag = this.CellMouseMove != null; if (flag) { this.CellMouseMove(this, args); } } internal void RaiseSelectionRangeChanged(RangeEventArgs args) { EventHandler selectionRangeChanged = this.SelectionRangeChanged; if (selectionRangeChanged != null) { selectionRangeChanged(this, args); } } public IUserVisual FocusVisual { get { IViewportController viewportController = this.viewportController; return (viewportController != null) ? viewportController.FocusVisual : null; } } internal bool OnKeyDown(KeyCode keyData) { bool flag = !this.FocusPos.IsEmpty && this.BeforeCellKeyDown != null; if (flag) { BeforeCellKeyDownEventArgs beforeCellKeyDownEventArgs = new BeforeCellKeyDownEventArgs { Cell = this.GetCell(this.selStart), CellPosition = this.selStart, KeyCode = keyData }; this.BeforeCellKeyDown(this, beforeCellKeyDownEventArgs); bool isCancelled = beforeCellKeyDownEventArgs.IsCancelled; if (isCancelled) { return true; } } bool flag2 = false; bool flag3 = !this.IsEditing && !this.selStart.IsEmpty; if (flag3) { Cell cell = this.cells[this.selStart.Row, this.selStart.Col]; bool flag4 = cell != null && cell.body != null; if (flag4) { flag2 = cell.body.OnKeyDown(keyData); bool flag5 = flag2; if (flag5) { this.RequestInvalidate(); } } } bool flag6 = this.waitingEndDirection; bool flag7 = keyData != (KeyCode.ShiftKey | KeyCode.Shift) && keyData != (KeyCode.LButton | KeyCode.ShiftKey | KeyCode.Control); if (flag7) { this.waitingEndDirection = false; } bool flag8 = !flag2; if (flag8) { flag2 = true; if (keyData <= (KeyCode.LButton | KeyCode.MButton | KeyCode.Back | KeyCode.Shift)) { if (keyData <= KeyCode.Delete) { if (keyData <= KeyCode.Tab) { if (keyData == KeyCode.Back) { bool flag9 = !this.selStart.IsEmpty; if (flag9) { this.StartEdit(this.selStart); this.controlAdapter.SetEditControlText(string.Empty); } goto IL_7D2; } if (keyData != KeyCode.Tab) { goto IL_7CE; } this.OnTabKeyPressed(false); goto IL_7D2; } else { if (keyData == KeyCode.Enter) { this.OnEnterKeyPressed(false); goto IL_7D2; } switch (keyData) { case KeyCode.Prior: this.MoveSelectionPageUp(false); goto IL_7D2; case KeyCode.Next: this.MoveSelectionPageDown(false); goto IL_7D2; case KeyCode.End: break; case KeyCode.Home: this.MoveSelectionHome(RowOrColumn.Column, false); goto IL_7D2; case KeyCode.Left: { bool flag10 = flag6; if (flag10) { this.MoveSelectionHome(RowOrColumn.Column, false); } else { this.MoveSelectionLeft(false); } goto IL_7D2; } case KeyCode.Up: { bool flag11 = flag6; if (flag11) { this.MoveSelectionHome(RowOrColumn.Row, false); } else { this.MoveSelectionUp(false); } goto IL_7D2; } case KeyCode.Right: { bool flag12 = flag6; if (flag12) { this.MoveSelectionEnd(RowOrColumn.Column, false); } else { this.MoveSelectionRight(false); } goto IL_7D2; } case KeyCode.Down: { bool flag13 = flag6; if (flag13) { this.MoveSelectionEnd(RowOrColumn.Row, false); } else { this.MoveSelectionDown(false); } goto IL_7D2; } case KeyCode.Select: case KeyCode.Print: case KeyCode.Execute: case KeyCode.PrintScreen: case KeyCode.Insert: goto IL_7CE; case KeyCode.Delete: { bool flag14 = this.controlAdapter != null && !this.HasSettings(WorksheetSettings.Edit_Readonly); if (flag14) { IActionControl actionControl = this.controlAdapter.ControlInstance as IActionControl; bool flag15 = actionControl != null; if (flag15) { actionControl.DoAction(this, new RemoveRangeDataAction(this.selectionRange)); } } goto IL_7D2; } default: goto IL_7CE; } } } else if (keyData <= KeyCode.F4) { if (keyData == KeyCode.F2) { this.StartEdit(); goto IL_7D2; } if (keyData != KeyCode.F4) { goto IL_7CE; } bool flag16 = this.controlAdapter != null; if (flag16) { IActionControl actionControl2 = this.controlAdapter.ControlInstance as IActionControl; bool flag17 = actionControl2 != null; if (flag17) { actionControl2.RepeatLastAction(this.selectionRange); } } goto IL_7D2; } else { if (keyData == (KeyCode.LButton | KeyCode.Back | KeyCode.Shift)) { this.OnTabKeyPressed(true); goto IL_7D2; } if (keyData != (KeyCode.LButton | KeyCode.MButton | KeyCode.Back | KeyCode.Shift)) { goto IL_7CE; } this.OnEnterKeyPressed(true); goto IL_7D2; } } else if (keyData <= (KeyCode)131137) { if (keyData <= (KeyCode.Back | KeyCode.Space | KeyCode.Control)) { switch (keyData) { case KeyCode.LButton | KeyCode.Space | KeyCode.Shift: this.MoveSelectionPageUp(true); goto IL_7D2; case KeyCode.RButton | KeyCode.Space | KeyCode.Shift: this.MoveSelectionPageDown(true); goto IL_7D2; case KeyCode.LButton | KeyCode.RButton | KeyCode.Space | KeyCode.Shift: break; case KeyCode.MButton | KeyCode.Space | KeyCode.Shift: this.MoveSelectionHome(RowOrColumn.Column, true); goto IL_7D2; case KeyCode.LButton | KeyCode.MButton | KeyCode.Space | KeyCode.Shift: { bool flag18 = this.selectionMode != WorksheetSelectionMode.None && this.selEnd.Col > 0; if (flag18) { bool flag19 = flag6; if (flag19) { this.MoveSelectionHome(RowOrColumn.Column, true); } else { this.MoveSelectionLeft(true); } } goto IL_7D2; } case KeyCode.RButton | KeyCode.MButton | KeyCode.Space | KeyCode.Shift: { bool flag20 = this.selectionMode != WorksheetSelectionMode.None && this.selEnd.Row > 0; if (flag20) { bool flag21 = flag6; if (flag21) { this.MoveSelectionHome(RowOrColumn.Row, true); } else { this.MoveSelectionUp(true); } } goto IL_7D2; } case KeyCode.LButton | KeyCode.RButton | KeyCode.MButton | KeyCode.Space | KeyCode.Shift: { bool flag22 = this.selectionMode != WorksheetSelectionMode.None && this.selEnd.Col < this.cols.Count - 1; if (flag22) { bool flag23 = flag6; if (flag23) { this.MoveSelectionEnd(RowOrColumn.Column, true); } else { this.MoveSelectionRight(true); } } goto IL_7D2; } case KeyCode.Back | KeyCode.Space | KeyCode.Shift: { bool flag24 = this.selectionMode != WorksheetSelectionMode.None && this.selEnd.Row < this.rows.Count - 1; if (flag24) { bool flag25 = flag6; if (flag25) { this.MoveSelectionEnd(RowOrColumn.Row, true); } else { this.MoveSelectionDown(true); } } goto IL_7D2; } default: switch (keyData) { case KeyCode.LButton | KeyCode.RButton | KeyCode.Space | KeyCode.Control: this.MoveSelectionEnd(RowOrColumn.Both, false); goto IL_7D2; case KeyCode.MButton | KeyCode.Space | KeyCode.Control: this.MoveSelectionHome(RowOrColumn.Both, false); goto IL_7D2; case KeyCode.LButton | KeyCode.MButton | KeyCode.Space | KeyCode.Control: this.MoveSelectionHome(RowOrColumn.Column, false); goto IL_7D2; case KeyCode.RButton | KeyCode.MButton | KeyCode.Space | KeyCode.Control: this.MoveSelectionHome(RowOrColumn.Row, false); goto IL_7D2; case KeyCode.LButton | KeyCode.RButton | KeyCode.MButton | KeyCode.Space | KeyCode.Control: this.MoveSelectionEnd(RowOrColumn.Column, false); goto IL_7D2; case KeyCode.Back | KeyCode.Space | KeyCode.Control: this.MoveSelectionEnd(RowOrColumn.Row, false); goto IL_7D2; default: goto IL_7CE; } break; } } else { if (keyData == (KeyCode.ShiftKey | KeyCode.Space | KeyCode.Control)) { bool flag26 = this.HasSettings(WorksheetSettings.Behavior_ShortcutKeyToZoom); if (flag26) { this.ZoomReset(); } goto IL_7D2; } if (keyData != (KeyCode)131137) { goto IL_7CE; } this.SelectAll(); goto IL_7D2; } } else if (keyData <= (KeyCode)131162) { if (keyData == (KeyCode)131139) { this.Copy(); goto IL_7D2; } switch (keyData) { case (KeyCode)131158: this.Paste(); goto IL_7D2; case (KeyCode)131159: goto IL_7CE; case (KeyCode)131160: this.Cut(true); goto IL_7D2; case (KeyCode)131161: { bool flag27 = this.controlAdapter != null && !this.HasSettings(WorksheetSettings.Edit_Readonly); if (flag27) { IActionControl actionControl3 = this.controlAdapter.ControlInstance as IActionControl; bool flag28 = actionControl3 != null; if (flag28) { actionControl3.Redo(); } } goto IL_7D2; } case (KeyCode)131162: { bool flag29 = this.controlAdapter != null && !this.HasSettings(WorksheetSettings.Edit_Readonly); if (flag29) { IActionControl actionControl4 = this.controlAdapter.ControlInstance as IActionControl; bool flag30 = actionControl4 != null; if (flag30) { actionControl4.Undo(); } } goto IL_7D2; } default: goto IL_7CE; } } else { if (keyData == (KeyCode.LButton | KeyCode.RButton | KeyCode.Back | KeyCode.ShiftKey | KeyCode.Space | KeyCode.F17 | KeyCode.Control)) { bool flag31 = this.HasSettings(WorksheetSettings.Behavior_ShortcutKeyToZoom); if (flag31) { this.ZoomIn(); } goto IL_7D2; } if (keyData == (KeyCode.LButton | KeyCode.MButton | KeyCode.Back | KeyCode.ShiftKey | KeyCode.Space | KeyCode.F17 | KeyCode.Control)) { bool flag32 = this.HasSettings(WorksheetSettings.Behavior_ShortcutKeyToZoom); if (flag32) { this.ZoomOut(); } goto IL_7D2; } switch (keyData) { case KeyCode.LButton | KeyCode.RButton | KeyCode.Space | KeyCode.Shift | KeyCode.Control: this.MoveSelectionEnd(RowOrColumn.Both, true); goto IL_7D2; case KeyCode.MButton | KeyCode.Space | KeyCode.Shift | KeyCode.Control: this.MoveSelectionHome(RowOrColumn.Both, true); goto IL_7D2; case KeyCode.LButton | KeyCode.MButton | KeyCode.Space | KeyCode.Shift | KeyCode.Control: this.MoveSelectionHome(RowOrColumn.Column, true); goto IL_7D2; case KeyCode.RButton | KeyCode.MButton | KeyCode.Space | KeyCode.Shift | KeyCode.Control: this.MoveSelectionHome(RowOrColumn.Row, true); goto IL_7D2; case KeyCode.LButton | KeyCode.RButton | KeyCode.MButton | KeyCode.Space | KeyCode.Shift | KeyCode.Control: this.MoveSelectionEnd(RowOrColumn.Column, true); goto IL_7D2; case KeyCode.Back | KeyCode.Space | KeyCode.Shift | KeyCode.Control: this.MoveSelectionEnd(RowOrColumn.Row, true); goto IL_7D2; default: goto IL_7CE; } } this.waitingEndDirection = true; goto IL_7D2; IL_7CE: flag2 = false; IL_7D2: bool flag33 = !this.selStart.IsEmpty && this.AfterCellKeyDown != null; if (flag33) { AfterCellKeyDownEventArgs e = new AfterCellKeyDownEventArgs { Cell = this.GetCell(this.selStart), CellPosition = this.selStart, KeyCode = keyData }; this.AfterCellKeyDown(this, e); } } return flag2; } internal bool OnKeyUp(KeyCode keyData) { bool flag = !this.selStart.IsEmpty && !this.DropKeyUpAfterEndEdit; if (flag) { Cell cell = this.cells[this.selStart.Row, this.selStart.Col]; bool flag2 = cell != null && cell.body != null; if (flag2) { bool flag3 = cell.body.OnKeyUp(keyData); bool flag4 = flag3; if (flag4) { this.RequestInvalidate(); } } } this.DropKeyUpAfterEndEdit = false; EventHandler cellKeyUp = this.CellKeyUp; if (cellKeyUp != null) { cellKeyUp(this, new CellKeyDownEventArgs { Cell = this.GetCell(this.selStart), CellPosition = this.selStart, KeyCode = keyData }); } return true; } internal bool DropKeyUpAfterEndEdit { get; set; } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler BeforeCellKeyDown; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler AfterCellKeyDown; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler CellKeyUp; internal void DoAction(BaseWorksheetAction action) { bool flag = this.workbook == null; if (flag) { throw new InvalidOperationException("Worksheet need to be added into workbook before doing actions."); } IActionControl actionControl = (this.controlAdapter == null) ? null : (this.controlAdapter.ControlInstance as IActionControl); bool flag2 = actionControl != null; if (flag2) { actionControl.DoAction(this, action); } } internal void PickRange(Func onPicked) { this.whenRangePicked = onPicked; } internal void EndPickRange() { bool flag = this.whenRangePicked != null; if (flag) { this.whenRangePicked = null; bool flag2 = this.controlAdapter != null; if (flag2) { IRangePickableControl rangePickableControl = this.controlAdapter.ControlInstance as IRangePickableControl; bool flag3 = rangePickableControl != null; if (flag3) { rangePickableControl.EndPickRange(); } } } } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler Resetted; internal void NotifyExceptionHappen(Exception ex) { bool flag = this.workbook != null; if (flag) { this.workbook.NotifyExceptionHappen(this, ex); } } public void EnableSettings(WorksheetSettings settings) { this.SetSettings(settings, true); } public void DisableSettings(WorksheetSettings settings) { this.SetSettings(settings, false); } public void SetSettings(WorksheetSettings settings, bool value) { if (value) { this.settings |= settings; } else { this.settings &= ~settings; } bool flag = this.viewportController != null; if (flag) { bool flag2 = (settings & WorksheetSettings.View_ShowColumnHeader) == WorksheetSettings.View_ShowColumnHeader || (settings & WorksheetSettings.View_ShowRowHeader) == WorksheetSettings.View_ShowRowHeader; if (flag2) { ViewTypes viewTypes = ViewTypes.None; bool flag3 = (settings & WorksheetSettings.View_ShowColumnHeader) == WorksheetSettings.View_ShowColumnHeader; if (flag3) { viewTypes |= ViewTypes.ColumnHeader; } bool flag4 = (settings & WorksheetSettings.View_ShowRowHeader) == WorksheetSettings.View_ShowRowHeader; if (flag4) { viewTypes |= ViewTypes.RowHeader; } this.viewportController.SetViewVisible(viewTypes, value); } bool flag5 = settings.Has(WorksheetSettings.View_AllowShowRowOutlines) && this.outlines != null && this.outlines[RowOrColumn.Row] != null; if (flag5) { this.viewportController.SetViewVisible(ViewTypes.RowOutline, value); } bool flag6 = settings.HasAny(WorksheetSettings.View_AllowShowColumnOutlines) && this.outlines != null && this.outlines[RowOrColumn.Column] != null; if (flag6) { this.viewportController.SetViewVisible(ViewTypes.ColOutline, value); } } bool flag7 = settings.Has(WorksheetSettings.View_ShowPageBreaks) && value; if (flag7) { this.AutoSplitPage(); } bool flag8 = this.SettingsChanged != null; if (flag8) { this.SettingsChanged(this, new SettingsChangedEventArgs { AddedSettings = (value ? settings : WorksheetSettings.None), RemovedSettings = ((!value) ? settings : WorksheetSettings.None) }); } bool flag9 = this.controlAdapter != null; if (flag9) { this.UpdateViewportControllBounds(); this.RequestInvalidate(); } } public bool HasSettings(WorksheetSettings setting) { return (this.settings & setting) == setting; } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler SettingsChanged; public float IndentSize { get { return this.indentSize; } set { this.indentSize = value; } } public void ExportAsHTML(Stream s) { this.ExportAsHTML(s, null, true); } public void ExportAsHTML(Stream s, string pageTitle, bool exportHeader = true) { RGHTMLExporter.Export(s, this, string.IsNullOrEmpty(pageTitle) ? "Exported ReoGrid" : pageTitle, exportHeader); } public override string ToString() { return string.Format("Worksheet[{0}]", this.name); } public void Dispose() { bool flag = this.workbook != null; if (flag) { bool flag2 = this.workbook.worksheets.Contains(this); if (flag2) { throw new InvalidOperationException("Cannot dispose a worksheet that is still contained in a workbook. Remove from workbook and try again."); } } this.workbook = null; this.rows.Clear(); this.cols.Clear(); this.rowHeaderCollection = null; this.colHeaderCollection = null; this.cells.Reset(); this.hBorders.Reset(); this.vBorders.Reset(); this.controlAdapter = null; bool flag3 = this.outlines != null; if (flag3) { this.outlines.Clear(); } this.rowOutlineCollection = null; this.columnOutlineCollection = null; bool flag4 = this.pageBreakCols != null; if (flag4) { this.pageBreakCols.Clear(); } bool flag5 = this.pageBreakRows != null; if (flag5) { this.pageBreakRows.Clear(); } bool flag6 = this.userPageBreakCols != null; if (flag6) { this.userPageBreakCols.Clear(); } bool flag7 = this.userPageBreakRows != null; if (flag7) { this.userPageBreakRows.Clear(); } this.pageBreakRowCollection = null; this.pageBreakColumnCollection = null; bool flag8 = this.formulaRanges != null; if (flag8) { this.formulaRanges.Clear(); } bool flag9 = this.drawingCanvas != null; if (flag9) { this.drawingCanvas.Clear(); } } internal Index4DArray hBorders = new Index4DArray(); internal Index4DArray vBorders = new Index4DArray(); internal bool viewDirty = false; private bool suspendDataChangedEvent; private RangePosition currentCopingRange = RangePosition.Empty; internal Dictionary cellComments = null; internal Dictionary visibleCellComments = null; internal WorksheetDrawingCanvas drawingCanvas; private Dictionary> formulaRanges = new Dictionary>(); internal Dictionary> traceDependentArrows = null; internal List cols = new List(100); internal List rows = new List(200); internal ushort colHeaderHeight = 18; internal ushort rowHeaderWidth = 40; internal ushort defaultColumnWidth = Worksheet.InitDefaultColumnWidth; internal ushort defaultRowHeight = Worksheet.InitDefaultRowHeight; private bool userRowHeaderWidth = false; private Worksheet.RowHeaderCollection rowHeaderCollection; private Worksheet.ColumnHeaderCollection colHeaderCollection; private RowOutlineCollection rowOutlineCollection; private ColumnOutlineCollection columnOutlineCollection; internal Dictionary> outlines; private PrintSettings printSettings; private RangePosition printableRange = RangePosition.Empty; internal List pageBreakRows = null; internal List pageBreakCols = null; internal List userPageBreakRows = null; internal List userPageBreakCols = null; private Worksheet.RowPageBreakIndexCollection pageBreakRowCollection; private Worksheet.ColumnPageBreakIndexCollection pageBreakColumnCollection; private Worksheet.ReoGridRangeCollection rangeCollection; private static readonly Color[] NamedRangeHighlightColors = new Color[] { Color.Blue, Color.Green, Color.Purple, Color.Brown, Color.SeaGreen, Color.Orange, Color.IndianRed }; internal HighlightRange focusHighlightRange; private byte rangeHighlightColorCounter = 0; internal byte focusHighlightRangeRunningOffset = 0; internal List highlightRanges = new List(); private Worksheet.HighlightRangeCollection highlightRangeCollection; internal Dictionary registeredNamedRanges = new Dictionary(); private NamedRangeCollection namedRangeCollection = null; private bool suspendingUIUpdates = false; private IViewportController viewportController; internal bool isLeadHeadSelected = false; internal Cell currentEditingCell; private string backupData; private bool endEditProcessing = false; internal CellPosition selStart = new CellPosition(0, 0); internal CellPosition selEnd = new CellPosition(0, 0); internal CellPosition focusPos = new CellPosition(0, 0); private int focusReturnColumn = 0; private FocusPosStyle focusPosStyle = FocusPosStyle.Default; internal CellPosition hoverPos; internal RangePosition selectionRange = new RangePosition(0, 0, 1, 1); internal WorksheetSelectionMode selectionMode = WorksheetSelectionMode.Range; private WorksheetSelectionStyle selectionStyle = WorksheetSelectionStyle.Default; private SelectionForwardDirection selectionForwardDirection; internal IControlAdapter controlAdapter; public static readonly ushort InitDefaultColumnWidth = 70; public static readonly ushort InitDefaultRowHeight = 20; internal const int DefaultCols = 100; internal const int DefaultRows = 200; internal const int OutlineButtonSize = 13; public static readonly WorksheetRangeStyle DefaultStyle = new WorksheetRangeStyle { Flag = (PlainStyleFlag)24579L, FontName = "Calibri", FontSize = 10.25f, HAlign = ReoGridHorAlign.General, VAlign = ReoGridVerAlign.General }; internal Workbook workbook; private string name; private Color nameBackColor = Color.Transparent; private Color nameTextColor = Color.Transparent; private static readonly float minScaleFactor = 0.1f; private static readonly float maxScaleFactor = 4f; private float _scaleFactor = 1f; internal float renderScaleFactor = 1f; internal Index4DArray cells = new Index4DArray(); private int maxColumnHeader = -1; private int maxRowHeader = -1; private Worksheet.CellCollection cellCollection; internal OperationStatus operationStatus = OperationStatus.Default; internal int currentColWidthChanging = -1; internal int currentRowHeightChanging = -1; internal int pageBreakAdjustFocusIndex = -1; internal int pageBreakAdjustRow = -1; internal int pageBreakAdjustCol = -1; internal Cell mouseCapturedCell = null; internal float headerAdjustNewValue = 0f; internal Point lastMouseMoving; internal RangePosition lastChangedSelectionRange; internal RangePosition draggingSelectionRange; internal CellPosition focusMovingRangeOffset; private bool waitingEndDirection; internal Func whenRangePicked; internal WorksheetSettings settings; private float indentSize; public class RowHeaderCollection : IEnumerable, IEnumerable { internal Worksheet GridControl { get; set; } internal RowHeaderCollection(Worksheet grid) { this.GridControl = grid; } public RowHeader this[int index] { get { Worksheet gridControl = this.GridControl; return (index < 0 || index >= gridControl.rows.Count) ? null : gridControl.rows[index]; } } private IEnumerator GetEnum() { return this.GridControl.rows.GetEnumerator(); } public IEnumerator GetEnumerator() { return this.GetEnum(); } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnum(); } } public class ColumnHeaderCollection : IEnumerable, IEnumerable { internal Worksheet GridControl { get; set; } internal ColumnHeaderCollection(Worksheet grid) { this.GridControl = grid; } public ColumnHeader this[int index] { get { Worksheet gridControl = this.GridControl; return (index < 0 || index >= gridControl.cols.Count) ? null : gridControl.cols[index]; } } public ColumnHeader this[string address] { get { int numberOfChar = RGUtility.GetNumberOfChar(address); return this[numberOfChar]; } } private IEnumerator GetEnum() { return this.GridControl.cols.GetEnumerator(); } public IEnumerator GetEnumerator() { return this.GetEnum(); } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnum(); } } public class RowPageBreakIndexCollection : ICollection, IEnumerable, IEnumerable { private Worksheet Worksheet { get; set; } internal RowPageBreakIndexCollection(Worksheet sheet) { this.Worksheet = sheet; } private List ValidPageBreakArray { get { return (this.Worksheet.pageBreakRows != null && this.Worksheet.pageBreakRows.Count > 1) ? this.Worksheet.pageBreakRows : this.Worksheet.userPageBreakRows; } } private IEnumerator GetEnum() { bool flag = this.Worksheet == null; if (flag) { throw new ReferenceObjectNotAssociatedException("Collection of row page breaks must be created from valid instance of ReoGrid control."); } return this.ValidPageBreakArray.GetEnumerator(); } public IEnumerator GetEnumerator() { return this.GetEnum(); } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnum(); } public void Add(int rowIndex) { bool flag = this.Worksheet == null; if (flag) { throw new ReferenceObjectNotAssociatedException("Collection of row page break must be created from valid grid control."); } this.Worksheet.InsertRowPageBreak(rowIndex, true); } public void Clear() { bool flag = this.Worksheet == null; if (flag) { throw new ReferenceObjectNotAssociatedException("Collection of row page break must be created from valid grid control."); } this.Worksheet.ClearRowPageBreaks(); } public bool Contains(int index) { return this.ValidPageBreakArray != null && this.ValidPageBreakArray.Contains(index); } public void CopyTo(int[] array, int arrayIndex) { this.ValidPageBreakArray.CopyTo(array, arrayIndex); } public int Count { get { return this.ValidPageBreakArray.Count; } } public bool IsReadOnly { get { return false; } } public bool Remove(int rowIndex) { bool flag = this.Worksheet == null; if (flag) { throw new ReferenceObjectNotAssociatedException("Collection of row page break must be created from valid grid control."); } bool result; try { this.Worksheet.RemoveRowPageBreak(rowIndex); result = true; } catch { result = false; } return result; } public int this[int index] { get { return this.ValidPageBreakArray[index]; } set { this.Worksheet.ChangeRowPageBreak(index, value, true); } } } public class ColumnPageBreakIndexCollection : ICollection, IEnumerable, IEnumerable { private Worksheet Worksheet { get; set; } internal ColumnPageBreakIndexCollection(Worksheet sheet) { this.Worksheet = sheet; } private List ValidPageBreakArray { get { return (this.Worksheet.pageBreakCols != null && this.Worksheet.pageBreakCols.Count > 1) ? this.Worksheet.pageBreakCols : this.Worksheet.userPageBreakCols; } } private IEnumerator GetEnum() { bool flag = this.Worksheet == null; if (flag) { throw new ReferenceObjectNotAssociatedException("Collection of column page breaks must be created from valid instance of ReoGrid control."); } this.Worksheet.CheckAndInitPrintableRegion(); return this.ValidPageBreakArray.GetEnumerator(); } public IEnumerator GetEnumerator() { return this.GetEnum(); } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnum(); } public void Add(int columnIndex) { bool flag = this.Worksheet == null; if (flag) { throw new ReferenceObjectNotAssociatedException("Collection of column page breaks must be created from valid instance of ReoGrid control."); } this.Worksheet.InsertColumnPageBreak(columnIndex, true); } public void Clear() { bool flag = this.Worksheet == null; if (flag) { throw new ReferenceObjectNotAssociatedException("Collection of column page breaks must be created from valid instance of ReoGrid control."); } this.Worksheet.ClearColumnPageBreaks(); } public bool Contains(int index) { return this.ValidPageBreakArray != null && this.ValidPageBreakArray.Contains(index); } public void CopyTo(int[] array, int arrayIndex) { this.ValidPageBreakArray.CopyTo(array, arrayIndex); } public int Count { get { return this.ValidPageBreakArray.Count; } } public bool IsReadOnly { get { return false; } } public bool Remove(int columnIndex) { bool flag = this.Worksheet == null; if (flag) { throw new ReferenceObjectNotAssociatedException("Collection of column page breaks must be created from valid instance of ReoGrid control."); } bool result; try { this.Worksheet.RemoveColumnPageBreak(columnIndex); result = true; } catch { result = false; } return result; } public int this[int index] { get { return this.ValidPageBreakArray[index]; } set { bool flag = this.ValidPageBreakArray.Count == 0; if (flag) { throw new PageBreakNotFoundException(index); } this.Worksheet.ChangeColumnPageBreak(index, value, true); } } } public class ReoGridRangeCollection { internal ReoGridRangeCollection(Worksheet grid) { this.worksheet = grid; } public ReferenceRange this[string address] { get { return new ReferenceRange(this.worksheet, address); } } public ReferenceRange this[int row, int col, int rows, int cols] { get { return new ReferenceRange(this.worksheet, this.worksheet.FixRange(new RangePosition(row, col, rows, cols))); } } public ReferenceRange this[CellPosition startPos, CellPosition endPos] { get { return new ReferenceRange(this.worksheet, this.worksheet.CreateAndGetCell(startPos), this.worksheet.CreateAndGetCell(endPos)); } } public ReferenceRange this[RangePosition range] { get { bool isEmpty = range.IsEmpty; if (isEmpty) { throw new ArgumentException("range position is empty", "range"); } return new ReferenceRange(this.worksheet, this.worksheet.FixRange(range)); } } private Worksheet worksheet; } internal class HighlightRangeCollection : ICollection, IEnumerable, IEnumerable { internal Worksheet Worksheet { get; private set; } public HighlightRangeCollection(Worksheet grid) { this.Worksheet = grid; } public HighlightRange Add(string address) { return this.Worksheet.AddHighlightRange(address); } public HighlightRange Add(RangePosition range) { return this.Worksheet.AddHighlightRange(range); } public void Add(HighlightRange item) { this.Worksheet.AddHighlightRange(item); } public void Clear() { this.Worksheet.RemoveAllHighlightRanges(); } public bool Contains(HighlightRange item) { return this.Worksheet.HasHighlightRange(item); } public void CopyTo(HighlightRange[] array, int arrayIndex) { this.Worksheet.highlightRanges.CopyTo(array, arrayIndex); } public int Count { get { return this.Worksheet.highlightRanges.Count; } } public bool IsReadOnly { get { throw new NotImplementedException(); } } public bool Remove(HighlightRange item) { return this.Worksheet.RemoveHighlightRange(item); } public IEnumerator GetEnumerator() { return this.Worksheet.highlightRanges.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return this.Worksheet.highlightRanges.GetEnumerator(); } } public class CellCollection : IEnumerable, IEnumerable { internal CellCollection(Worksheet grid) : this(grid, null) { } internal CellCollection(Worksheet grid, ReferenceRange range) { this.grid = grid; this.range = range; } public Cell this[string addressOrName] { get { bool flag = CellPosition.IsValidAddress(addressOrName); Cell result; if (flag) { result = this.grid.CreateAndGetCell(new CellPosition(addressOrName)); } else { bool flag2 = RGUtility.IsValidName(addressOrName); if (flag2) { NamedRange namedRange; bool flag3 = this.grid.registeredNamedRanges.TryGetValue(addressOrName, out namedRange); if (flag3) { return this.grid.CreateAndGetCell(namedRange.StartPos); } } result = null; } return result; } } public Cell this[int row, int col] { get { return this.grid.CreateAndGetCell(row, col); } } public Cell this[CellPosition pos] { get { return this[pos.Row, pos.Col]; } } private IEnumerator GetEnum() { bool flag = this.grid == null; if (flag) { throw new ReferenceObjectNotAssociatedException("Collection of cells must be associated with an valid ReoGrid control."); } RangePosition fixedRange = (this.range == null) ? RangePosition.EntireRange : this.grid.FixRange(this.range); int num; for (int r = fixedRange.Row; r <= fixedRange.EndRow; r = num + 1) { for (int c = fixedRange.Col; c <= fixedRange.EndCol; c = num + 1) { Cell cell = this.grid.cells[r, c]; bool flag2 = cell == null; if (flag2) { yield return this.grid.CreateCell(r, c, true); } else { bool flag3 = !cell.IsValidCell; if (!flag3) { yield return this.grid.CreateAndGetCell(r, c); cell = null; } } num = c; } num = r; } yield break; } public IEnumerator GetEnumerator() { return this.GetEnum(); } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnum(); } private Worksheet grid; private ReferenceRange range; } } }