Class that knows how to read an Excel worksheet containing edge data.
Call ReadWorksheet to read an edge worksheet.
상속: WorksheetReaderBase
        GetRequiredTables
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            out ListObject oEdgeTable,
            out ListObject oVertexTable
        )
        {
            Debug.Assert(oWorkbook != null);
            AssertValid();

            // Get the required table that contains edge data.  GetEdgeTable()
            // checks for the required vertex name columns.

            EdgeWorksheetReader oEdgeWorksheetReader = new EdgeWorksheetReader();

            oEdgeTable = oEdgeWorksheetReader.GetEdgeTable(oWorkbook);

            // Normally, the vertex table isn't required, but to avoid having to
            // create the table in code if it's missing, require it here.

            if (ExcelTableUtil.TryGetTable(oWorkbook, WorksheetNames.Vertices,
                                           TableNames.Vertices, out oVertexTable))
            {
                // Make sure the vertex name column exists.

                ListColumn oColumn;

                if (!ExcelTableUtil.TryGetTableColumn(oVertexTable,
                                                      VertexTableColumnNames.VertexName, out oColumn))
                {
                    oVertexTable = null;
                }
            }
            else
            {
                oVertexTable = null;
            }

            if (oVertexTable == null)
            {
                throw new WorkbookFormatException(String.Format(

                                                      "To use this feature, there must be a worksheet named \"{0}\""
                                                      + " that contains a table named \"{1}\", and that table must"
                                                      + " contain a column named \"{2}\"."
                                                      + "\r\n\r\n"
                                                      + "{3}"
                                                      ,
                                                      WorksheetNames.Vertices,
                                                      TableNames.Vertices,
                                                      VertexTableColumnNames.VertexName,
                                                      ErrorUtil.GetTemplateMessage()
                                                      ));
            }
        }
예제 #2
0
        GetDestinationEdgeTable
        (
            Microsoft.Office.Interop.Excel.Workbook oDestinationNodeXLWorkbook
        )
        {
            Debug.Assert(oDestinationNodeXLWorkbook != null);

            EdgeWorksheetReader oEdgeWorksheetReader = new EdgeWorksheetReader();

            return(oEdgeWorksheetReader.GetEdgeTable(
                       oDestinationNodeXLWorkbook));
        }
예제 #3
0
        ImportGraph
        (
            IGraph sourceGraph,
            String [] edgeAttributes,
            String [] vertexAttributes,
            Boolean clearTablesFirst,
            Microsoft.Office.Interop.Excel.Workbook destinationNodeXLWorkbook
        )
        {
            Debug.Assert(sourceGraph != null);
            Debug.Assert(destinationNodeXLWorkbook != null);

            if (clearTablesFirst)
            {
                NodeXLWorkbookUtil.ClearAllNodeXLTables(destinationNodeXLWorkbook);
            }

            // Get the required table that contains edge data.  GetEdgeTable()
            // throws an exception if the table is missing.

            EdgeWorksheetReader oEdgeWorksheetReader = new EdgeWorksheetReader();

            ListObject oEdgeTable =
                oEdgeWorksheetReader.GetEdgeTable(destinationNodeXLWorkbook);

            // Get the required columns.

            Range oVertex1NameColumnData = null;
            Range oVertex2NameColumnData = null;

            if (
                !ExcelTableUtil.TryGetTableColumnData(oEdgeTable,
                                                      EdgeTableColumnNames.Vertex1Name, out oVertex1NameColumnData)
                ||
                !ExcelTableUtil.TryGetTableColumnData(oEdgeTable,
                                                      EdgeTableColumnNames.Vertex2Name, out oVertex2NameColumnData)
                )
            {
                ErrorUtil.OnMissingColumn();
            }

            // Import the edges and their attributes into the workbook.

            ImportEdges(sourceGraph, edgeAttributes, oEdgeTable,
                        oVertex1NameColumnData, oVertex2NameColumnData, !clearTablesFirst);

            // Populate the vertex worksheet with the name of each unique vertex in
            // the edge worksheet.

            (new VertexWorksheetPopulator()).PopulateVertexWorksheet(
                destinationNodeXLWorkbook, false);

            // Get the table that contains vertex data.

            ListObject oVertexTable;
            Range      oVertexNameColumnData = null;
            Range      oVisibilityColumnData = null;

            if (
                !ExcelTableUtil.TryGetTable(destinationNodeXLWorkbook,
                                            WorksheetNames.Vertices, TableNames.Vertices, out oVertexTable)
                ||
                !ExcelTableUtil.TryGetTableColumnData(oVertexTable,
                                                      VertexTableColumnNames.VertexName, out oVertexNameColumnData)
                ||
                !ExcelTableUtil.TryGetTableColumnData(oVertexTable,
                                                      CommonTableColumnNames.Visibility, out oVisibilityColumnData)
                )
            {
                ErrorUtil.OnMissingColumn();
            }

            // Import isolated vertices and the attributes for all the graph's
            // vertices.

            ImportVertices(sourceGraph, vertexAttributes, oVertexTable,
                           oVertexNameColumnData, oVisibilityColumnData);
        }
    GetDestinationEdgeTable
    (
        Microsoft.Office.Interop.Excel.Workbook oDestinationNodeXLWorkbook
    )
    {
        Debug.Assert(oDestinationNodeXLWorkbook != null);

        EdgeWorksheetReader oEdgeWorksheetReader = new EdgeWorksheetReader();

        return ( oEdgeWorksheetReader.GetEdgeTable(
            oDestinationNodeXLWorkbook) );
    }
예제 #5
0
    ImportGraph
    (
        IGraph sourceGraph,
        String [] edgeAttributes,
        String [] vertexAttributes,
        Boolean clearTablesFirst,
        Microsoft.Office.Interop.Excel.Workbook destinationNodeXLWorkbook
    )
    {
        Debug.Assert(sourceGraph != null);
        Debug.Assert(destinationNodeXLWorkbook != null);

        if (clearTablesFirst)
        {
            NodeXLWorkbookUtil.ClearAllNodeXLTables(destinationNodeXLWorkbook);
        }

        // Get the required table that contains edge data.  GetEdgeTable()
        // throws an exception if the table is missing.

        EdgeWorksheetReader oEdgeWorksheetReader = new EdgeWorksheetReader();

        ListObject oEdgeTable =
            oEdgeWorksheetReader.GetEdgeTable(destinationNodeXLWorkbook);

        // Get the required columns.

        Range oVertex1NameColumnData = null;
        Range oVertex2NameColumnData = null;

        if (
            !ExcelTableUtil.TryGetTableColumnData(oEdgeTable,
                EdgeTableColumnNames.Vertex1Name, out oVertex1NameColumnData)
            ||
            !ExcelTableUtil.TryGetTableColumnData(oEdgeTable,
                EdgeTableColumnNames.Vertex2Name, out oVertex2NameColumnData)
            )
        {
            ErrorUtil.OnMissingColumn();
        }

        // Import the edges and their attributes into the workbook.

        ImportEdges(sourceGraph, edgeAttributes, oEdgeTable,
            oVertex1NameColumnData, oVertex2NameColumnData, !clearTablesFirst);

        // Populate the vertex worksheet with the name of each unique vertex in
        // the edge worksheet.

        ( new VertexWorksheetPopulator() ).PopulateVertexWorksheet(
            destinationNodeXLWorkbook, false);

        // Get the table that contains vertex data.

        ListObject oVertexTable;
        Range oVertexNameColumnData = null;
        Range oVisibilityColumnData = null;

        if (
            !ExcelTableUtil.TryGetTable(destinationNodeXLWorkbook,
                WorksheetNames.Vertices, TableNames.Vertices, out oVertexTable)
            ||
            !ExcelTableUtil.TryGetTableColumnData(oVertexTable,
                VertexTableColumnNames.VertexName, out oVertexNameColumnData)
            ||
            !ExcelTableUtil.TryGetTableColumnData(oVertexTable,
                CommonTableColumnNames.Visibility, out oVisibilityColumnData)
            )
        {
            ErrorUtil.OnMissingColumn();
        }

        // Import isolated vertices and the attributes for all the graph's
        // vertices.

        ImportVertices(sourceGraph, vertexAttributes, oVertexTable,
            oVertexNameColumnData, oVisibilityColumnData);
    }
예제 #6
0
        ReadWorkbookInternal
        (
            Microsoft.Office.Interop.Excel.Workbook workbook,
            ReadWorkbookContext readWorkbookContext
        )
        {
            Debug.Assert(readWorkbookContext != null);
            Debug.Assert(workbook != null);
            AssertValid();

            if (readWorkbookContext.PopulateVertexWorksheet)
            {
                // Create and use the object that fills in the vertex worksheet.

                VertexWorksheetPopulator oVertexWorksheetPopulator =
                    new VertexWorksheetPopulator();

                try
                {
                    oVertexWorksheetPopulator.PopulateVertexWorksheet(
                        workbook, false);
                }
                catch (WorkbookFormatException)
                {
                    // Ignore this type of error, which occurs when the vertex
                    // worksheet is missing, for example.
                }
            }

            // Create a graph with the appropriate directedness.

            PerWorkbookSettings oPerWorkbookSettings =
                new PerWorkbookSettings(workbook);

            IGraph oGraph = new Graph(oPerWorkbookSettings.GraphDirectedness);

            // Read the edge worksheet.  This adds data to oGraph,
            // ReadWorkbookContext.VertexNameDictionary, and
            // ReadWorkbookContext.EdgeIDDictionary.

            EdgeWorksheetReader oEdgeWorksheetReader = new EdgeWorksheetReader();

            oEdgeWorksheetReader.ReadWorksheet(workbook, readWorkbookContext,
                                               oGraph);

            oEdgeWorksheetReader = null;

            // Read the vertex worksheet.  This adds metadata to the vertices in
            // oGraph; adds any isolated vertices to oGraph and
            // ReadWorkbookContext.VertexNameDictionary; and removes any skipped
            // vertices (and their incident edges) from
            // ReadWorkbookContext.VertexNameDictionary,
            // ReadWorkbookContext.EdgeIDDictionary, and oGraph.

            VertexWorksheetReader oVertexWorksheetReader =
                new VertexWorksheetReader();

            oVertexWorksheetReader.ReadWorksheet(workbook, readWorkbookContext,
                                                 oGraph);

            oVertexWorksheetReader = null;

            if (readWorkbookContext.ReadGroups)
            {
                // Read the group worksheets.  This adds metadata to the vertices
                // in oGraph and to oGraph itself.

                GroupWorksheetReader oGroupWorksheetReader =
                    new GroupWorksheetReader();

                oGroupWorksheetReader.ReadWorksheet(workbook,
                                                    readWorkbookContext, oGraph);

                oGroupWorksheetReader = null;

                // Add to the graph any collapsed group attributes that can only be
                // added after the workbook is read.

                CollapsedGroupAttributeAdder.AddCollapsedGroupAttributes(
                    workbook, readWorkbookContext, oGraph);
            }

            return(oGraph);
        }
    GetRequiredTables
    (
        Microsoft.Office.Interop.Excel.Workbook oWorkbook,
        out ListObject oEdgeTable,
        out ListObject oVertexTable
    )
    {
        Debug.Assert(oWorkbook != null);
        AssertValid();

        // Get the required table that contains edge data.  GetEdgeTable()
        // checks for the required vertex name columns.

        EdgeWorksheetReader oEdgeWorksheetReader = new EdgeWorksheetReader();

        oEdgeTable = oEdgeWorksheetReader.GetEdgeTable(oWorkbook);

        // Normally, the vertex table isn't required, but to avoid having to
        // create the table in code if it's missing, require it here.

        if (ExcelTableUtil.TryGetTable(oWorkbook, WorksheetNames.Vertices,
            TableNames.Vertices, out oVertexTable) )
        {
            // Make sure the vertex name column exists.

            ListColumn oColumn;

            if (!ExcelTableUtil.TryGetTableColumn(oVertexTable,
                VertexTableColumnNames.VertexName, out oColumn) )
            {
                oVertexTable = null;
            }
        }
        else
        {
            oVertexTable = null;
        }

        if (oVertexTable == null)
        {
            throw new WorkbookFormatException(String.Format(

                "To use this feature, there must be a worksheet named \"{0}\""
                + " that contains a table named \"{1}\", and that table must"
                + " contain a column named \"{2}\"."
                + "\r\n\r\n"
                + "{3}"
                ,
                WorksheetNames.Vertices,
                TableNames.Vertices,
                VertexTableColumnNames.VertexName,
                ErrorUtil.GetTemplateMessage()
                ) );
        }
    }
예제 #8
0
    ReadWorkbookInternal
    (
        Microsoft.Office.Interop.Excel.Workbook workbook,
        ReadWorkbookContext readWorkbookContext
    )
    {
        Debug.Assert(readWorkbookContext != null);
        Debug.Assert(workbook != null);
        AssertValid();

        if (readWorkbookContext.PopulateVertexWorksheet)
        {
            // Create and use the object that fills in the vertex worksheet.

            VertexWorksheetPopulator oVertexWorksheetPopulator =
                new VertexWorksheetPopulator();

            try
            {
                oVertexWorksheetPopulator.PopulateVertexWorksheet(
                    workbook, false);
            }
            catch (WorkbookFormatException)
            {
                // Ignore this type of error, which occurs when the vertex
                // worksheet is missing, for example.
            }
        }

        // Create a graph with the appropriate directedness.

        PerWorkbookSettings oPerWorkbookSettings =
            new PerWorkbookSettings(workbook);

        IGraph oGraph = new Graph(oPerWorkbookSettings.GraphDirectedness);

        // Read the edge worksheet.  This adds data to oGraph, 
        // ReadWorkbookContext.VertexNameDictionary, and
        // ReadWorkbookContext.EdgeIDDictionary.

        EdgeWorksheetReader oEdgeWorksheetReader = new EdgeWorksheetReader();

        oEdgeWorksheetReader.ReadWorksheet(workbook, readWorkbookContext,
            oGraph);

        oEdgeWorksheetReader = null;

        // Read the vertex worksheet.  This adds metadata to the vertices in
        // oGraph; adds any isolated vertices to oGraph and
        // ReadWorkbookContext.VertexNameDictionary; and removes any skipped
        // vertices (and their incident edges) from
        // ReadWorkbookContext.VertexNameDictionary,
        // ReadWorkbookContext.EdgeIDDictionary, and oGraph.

        VertexWorksheetReader oVertexWorksheetReader =
            new VertexWorksheetReader();

        oVertexWorksheetReader.ReadWorksheet(workbook, readWorkbookContext,
            oGraph);

        oVertexWorksheetReader = null;

        if (readWorkbookContext.ReadGroups)
        {
            // Read the group worksheets.  This adds metadata to the vertices
            // in oGraph and to oGraph itself.

            GroupWorksheetReader oGroupWorksheetReader =
                new GroupWorksheetReader();

            oGroupWorksheetReader.ReadWorksheet(workbook,
                readWorkbookContext, oGraph);

            oGroupWorksheetReader = null;

            // Add to the graph any collapsed group attributes that can only be
            // added after the workbook is read.

            CollapsedGroupAttributeAdder.AddCollapsedGroupAttributes(
                workbook, readWorkbookContext, oGraph);
        }

        return (oGraph);
    }
    OnLoad
    (
        EventArgs e
    )
    {
        AssertValid();

        base.OnLoad(e);

        // Get the required edge table before the user does anything in the
        // dialog.

        EdgeWorksheetReader oEdgeWorksheetReader = new EdgeWorksheetReader();

        try
        {
            m_oEdgeTable = oEdgeWorksheetReader.GetEdgeTable(m_oWorkbook);
        }
        catch (Exception oException)
        {
            // The edge table couldn't be found.  Tell the user and close the
            // dialog.

            ErrorUtil.OnException(oException);

            this.Close();

            return;
        }
    }