Пример #1
0
        public void saveGraph(IGraph graph)
        {
            GraphMLGraphAdapter graphMlAdapter = new Smrf.NodeXL.Adapters.GraphMLGraphAdapter();

            FileStream fs = File.Create("graph.graphml");

            graphMlAdapter.SaveGraph(graph, fs);
        }
    GetGraphML
    (
        Microsoft.Office.Interop.Excel.Workbook oWorkbook
    )
    {
        Debug.Assert(oWorkbook != null);

        String sGraphML = null;

        // The graph owned by the NodeXLControl can't be used, because it
        // doesn't include all the edge and vertex column data needed for
        // GraphML.  Instead, read the graph from the workbook and include all
        // the necessary data.

        ReadWorkbookContext oReadWorkbookContext = new ReadWorkbookContext();
        oReadWorkbookContext.ReadAllEdgeAndVertexColumns = true;

        WorkbookReader oWorkbookReader = new WorkbookReader();

        IGraph oGraphForGraphML = oWorkbookReader.ReadWorkbook(
            oWorkbook, oReadWorkbookContext);

        GraphMLGraphAdapter oGraphMLGraphAdapter = new GraphMLGraphAdapter();

        using ( MemoryStream oMemoryStream = new MemoryStream() )
        {
            oGraphMLGraphAdapter.SaveGraph(oGraphForGraphML, oMemoryStream);
            oMemoryStream.Position = 0;

            using ( StreamReader oStreamReader =
                new StreamReader(oMemoryStream) )
            {
                sGraphML = oStreamReader.ReadToEnd();
            }
        }

        return (sGraphML);
    }