GetRows() { AssertValid(); // Get the visible range. If the table is filtered, the range may // contain multiple areas. Range oVisibleTableRange; if (!ExcelTableUtil.TryGetVisibleTableRange(m_oTable, out oVisibleTableRange)) { yield break; } // Loop through the areas, and split each area into subranges if the // area contains too many rows. ExcelTableRow oExcelTableRow = new ExcelTableRow(this); foreach (Range oSubrange in ExcelRangeSplitter.SplitRange(oVisibleTableRange)) { m_oCurrentSubrange = oSubrange; m_aoCurrentSubrangeValues = ExcelUtil.GetRangeValues( m_oCurrentSubrange); Int32 iRows = m_oCurrentSubrange.Rows.Count; for (m_iCurrentRowOneBased = 1; m_iCurrentRowOneBased <= iRows; m_iCurrentRowOneBased++) { // Note that the same ExcelTableRow object is always returned, // and the object doesn't know anything about the current row. // The current row information is maintained by this class, not // by ExcelTableRow, and ExcelTableRow forwards all its method // calls to this class. yield return(oExcelTableRow); } } m_oCurrentSubrange = null; m_aoCurrentSubrangeValues = null; m_iCurrentRowOneBased = Int32.MinValue; }
//************************************************************************* // Method: GetRows() // /// <summary> /// Enumerates the rows in the table. /// </summary> /// /// <returns> /// An enumerable that enumerates the rows in the table. /// </returns> /// /// <remarks> /// Filtered rows are automatically skipped. /// </remarks> //************************************************************************* public IEnumerable<ExcelTableRow> GetRows() { AssertValid(); // Get the visible range. If the table is filtered, the range may // contain multiple areas. Range oVisibleTableRange; if ( !ExcelUtil.TryGetVisibleTableRange(m_oTable, out oVisibleTableRange) ) { yield break; } // Loop through the areas, and split each area into subranges if the // area contains too many rows. ExcelTableRow oExcelTableRow = new ExcelTableRow(this); foreach ( Range oSubrange in ExcelRangeSplitter.SplitRange(oVisibleTableRange) ) { m_oCurrentSubrange = oSubrange; m_aoCurrentSubrangeValues = ExcelUtil.GetRangeValues( m_oCurrentSubrange); Int32 iRows = m_oCurrentSubrange.Rows.Count; for (m_iCurrentRowOneBased = 1; m_iCurrentRowOneBased <= iRows; m_iCurrentRowOneBased++) { // Note that the same ExcelTableRow object is always returned, // and the object doesn't know anything about the current row. // The current row information is maintained by this class, not // by ExcelTableRow, and ExcelTableRow forwards all its method // calls to this class. yield return (oExcelTableRow); } } m_oCurrentSubrange = null; m_aoCurrentSubrangeValues = null; m_iCurrentRowOneBased = Int32.MinValue; }