Smrf.NodeXL.ExcelTemplate.MatrixWorkbookImporter.ImportMatrixWorkbook C# (CSharp) Method

ImportMatrixWorkbook() public method

public ImportMatrixWorkbook ( Microsoft application, String sourceWorkbookName, System.Boolean sourceWorkbookHasVertexNames, GraphDirectedness sourceWorkbookDirectedness ) : IGraph
application Microsoft
sourceWorkbookName String
sourceWorkbookHasVertexNames System.Boolean
sourceWorkbookDirectedness GraphDirectedness
return IGraph
    ImportMatrixWorkbook
    (
        Microsoft.Office.Interop.Excel.Application application,
        String sourceWorkbookName,
        Boolean sourceWorkbookHasVertexNames,
        GraphDirectedness sourceWorkbookDirectedness
    )
    {
        Debug.Assert(application != null);
        Debug.Assert( !String.IsNullOrEmpty(sourceWorkbookName) );
        AssertValid();

        // Get the active worksheet of the source workbook.

        Worksheet oSourceWorksheet = GetActiveSourceWorksheet(
            application, sourceWorkbookName);

        // Read or create the names of the vertices in the source workbook.

        String [] asVertexNames;
        Int32 iFirstEdgeWeightRowOneBased, iFirstEdgeWeightColumnOneBased;

        if (sourceWorkbookHasVertexNames)
        {
            asVertexNames = ReadVertexNames(oSourceWorksheet);
            iFirstEdgeWeightRowOneBased = iFirstEdgeWeightColumnOneBased = 2;
        }
        else
        {
            asVertexNames = CreateVertexNames(oSourceWorksheet);
            iFirstEdgeWeightRowOneBased = iFirstEdgeWeightColumnOneBased = 1;
        }

        Int32 iVertices = asVertexNames.Length;

        switch (sourceWorkbookDirectedness)
        {
            case GraphDirectedness.Directed:

                break;

            case GraphDirectedness.Undirected:

                CheckSymmetryOfUndirectedMatrix(oSourceWorksheet,
                    iFirstEdgeWeightRowOneBased,
                    iFirstEdgeWeightColumnOneBased, iVertices);

                break;

            default:

                Debug.Assert(false);
                break;
        }

        // Create a graph and populate it with the vertices.

        IGraph oGraph = new Graph(sourceWorkbookDirectedness);
        IVertexCollection oVertices = oGraph.Vertices;
        IVertex[] aoOrderedVertices = new IVertex[iVertices];

        for (Int32 i = 0; i < iVertices; i++)
        {
            IVertex oVertex = oVertices.Add();
            oVertex.Name = asVertexNames[i];
            aoOrderedVertices[i] = oVertex;
        }

        // Read the edges and import them into the graph.

        ReadEdges(oSourceWorksheet, iFirstEdgeWeightRowOneBased,
            iFirstEdgeWeightColumnOneBased, oGraph, aoOrderedVertices);

        return (oGraph);
    }

Usage Example

コード例 #1
0
        ImportFromMatrixWorkbook()
        {
            AssertValid();

            MatrixWorkbookImporter oMatrixWorkbookImporter =
                new MatrixWorkbookImporter();

            m_oGraph = oMatrixWorkbookImporter.ImportMatrixWorkbook(
                m_oDestinationNodeXLWorkbook.Application,
                this.SourceWorkbookName,

                m_oImportFromMatrixWorkbookDialogUserSettings.
                SourceWorkbookHasVertexNames,

                m_oImportFromMatrixWorkbookDialogUserSettings.
                SourceWorkbookDirectedness
                );
        }
All Usage Examples Of Smrf.NodeXL.ExcelTemplate.MatrixWorkbookImporter::ImportMatrixWorkbook