namespace com.azkoss.excellite { using System; using System.Collections; /// ///Enumerator used for iterating cells in a CellRange. /// public class CellRangeEnumerator : IEnumerator { // Methods internal CellRangeEnumerator(CellRange parent, bool onlyAllocated) { this.parent = parent; this.onlyAllocated = onlyAllocated; this.rowCollection = this.parent.Parent.Rows; if (this.onlyAllocated) { this.rowLimit = Math.Min((int) (this.rowCollection.Count - 1), this.parent.LastRowIndex); } else { this.rowLimit = this.parent.LastRowIndex; } this.Reset(); } /// ///Advances the enumerator to the next element of the cell range. /// /// ///true if the enumerator was successfully advanced to the next element; false if ///the enumerator has passed the end of the cell range. /// public bool MoveNext() { while (this.currentRow <= this.rowLimit) { int num1; if (this.onlyAllocated) { num1 = Math.Min((int) (this.rowCollection[this.currentRow].AllocatedCells.Count - 1), this.parent.LastColumnIndex); } else { num1 = this.parent.LastColumnIndex; } this.currentColumn++; if (this.currentColumn <= num1) { return true; } this.currentColumn = this.parent.FirstColumnIndex - 1; this.currentRow++; } return false; } /// ///Sets the enumerator to its initial position, which is one column before ///the first cell in the cell range. /// public void Reset() { this.currentRow = this.parent.FirstRowIndex; this.currentColumn = this.parent.FirstColumnIndex - 1; } // Properties /// ///Gets the current element in the cell range. /// public object Current { get { return this.CurrentCell; } } /// ///Gets the current ExcelCell in the cell range. /// public ExcelCell CurrentCell { get { if (this.parent.IsRowColumnOutOfRange(this.currentRow, this.currentColumn)) { throw new InvalidOperationException("Enumerator is not pointing to valid cell. Use Reset() and/or MoveNext() methods."); } return this.rowCollection[this.currentRow].AllocatedCells[this.currentColumn]; } } /// ///Current absolute column index in the cell range. /// public int CurrentColumn { get { return this.currentColumn; } } /// ///Current absolute row index in the cell range. /// public int CurrentRow { get { return this.currentRow; } } /// ///Parent CellRange. /// public CellRange Parent { get { return this.parent; } } // Fields private int currentColumn; private int currentRow; private bool onlyAllocated; private readonly CellRange parent; private ExcelRowCollection rowCollection; private int rowLimit; } }