Smrf.AppLib.ExcelTableReader.GetRows C# (CSharp) Method

GetRows() public method

public GetRows ( ) : IEnumerable
return IEnumerable
    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;
    }

Usage Example

    ReadGroupVertexTable
    (
        ListObject oGroupVertexTable,
        ReadWorkbookContext oReadWorkbookContext,
        Dictionary<String, ExcelTemplateGroupInfo> oGroupNameDictionary,
        IGraph oGraph
    )
    {
        Debug.Assert(oGroupVertexTable != null);
        Debug.Assert(oReadWorkbookContext != null);
        Debug.Assert(oGroupNameDictionary != null);
        Debug.Assert(oGraph != null);
        AssertValid();

        Dictionary<String, IVertex> oVertexNameDictionary =
            oReadWorkbookContext.VertexNameDictionary;

        ExcelTableReader oExcelTableReader =
            new ExcelTableReader(oGroupVertexTable);

        foreach ( ExcelTableReader.ExcelTableRow oRow in
            oExcelTableReader.GetRows() )
        {
            // Get the group vertex information from the row.

            String sGroupName, sVertexName;

            if (
                !oRow.TryGetNonEmptyStringFromCell(
                    GroupVertexTableColumnNames.GroupName, out sGroupName)
                ||
                !oRow.TryGetNonEmptyStringFromCell(
                    GroupVertexTableColumnNames.VertexName, out sVertexName)
                )
            {
                continue;
            }

            // Get the group information for the vertex.

            ExcelTemplateGroupInfo oExcelTemplateGroupInfo;
            IVertex oVertex;

            if (
                !oGroupNameDictionary.TryGetValue(sGroupName,
                    out oExcelTemplateGroupInfo)
                ||
                !oVertexNameDictionary.TryGetValue(sVertexName,
                    out oVertex)
                )
            {
                continue;
            }

            // If the vertex should get its color or shape from the group, set
            // the vertex's color or shape.

            Boolean bReadColorFromGroup, bReadShapeFromGroup;

            GetReadColorAndShapeFlags(oVertex, oExcelTemplateGroupInfo,
                oReadWorkbookContext, out bReadColorFromGroup,
                out bReadShapeFromGroup);

            if (bReadColorFromGroup)
            {
                oVertex.SetValue(ReservedMetadataKeys.PerColor,
                    oExcelTemplateGroupInfo.VertexColor);
            }

            if (bReadShapeFromGroup)
            {
                oVertex.SetValue(ReservedMetadataKeys.PerVertexShape,
                    oExcelTemplateGroupInfo.VertexShape);
            }

            oExcelTemplateGroupInfo.Vertices.AddLast(oVertex);
        }
    }
All Usage Examples Of Smrf.AppLib.ExcelTableReader::GetRows