ReadWorkbook() public method

public ReadWorkbook ( Microsoft workbook, ReadWorkbookContext readWorkbookContext ) : IGraph
workbook Microsoft
readWorkbookContext ReadWorkbookContext
return IGraph
Ejemplo n.º 1
0
        ReadWorkbook
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook
        )
        {
            Debug.Assert(oWorkbook != null);

            WorkbookReader oWorkbookReader = new WorkbookReader();

            ReadWorkbookContext oReadWorkbookContext = new ReadWorkbookContext();

            // Read all columns in the vertex worksheet and store the cell values
            // as metadata on the graph's vertices.

            oReadWorkbookContext.ReadAllEdgeAndVertexColumns = true;

            // GroupsToGraphMetricColumnsConverter.Convert() copies the ID column
            // on the vertex worksheet to the group-vertex worksheet, so make sure
            // that the vertex ID column is filled in.

            oReadWorkbookContext.FillIDColumns = true;

            return(oWorkbookReader.ReadWorkbook(oWorkbook,
                                                oReadWorkbookContext));
        }
        ReadWorkbook
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            IGraphMetricCalculator2 [] oGraphMetricCalculators
        )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(oGraphMetricCalculators != null);
            AssertValid();

            ReadWorkbookContext oReadWorkbookContext = new ReadWorkbookContext();

            oReadWorkbookContext.FillIDColumns           = true;
            oReadWorkbookContext.PopulateVertexWorksheet = true;
            oReadWorkbookContext.ReadGroups = true;

            // Some of the graph metric calculators, such as
            // TopItemsCalculatorBase2, need to rank vertices or edges by values in
            // a specified column.  Make those values available on the graph.

            oReadWorkbookContext.ReadAllEdgeAndVertexColumns = true;

            WorkbookReader oWorkbookReader = new WorkbookReader();

            return(oWorkbookReader.ReadWorkbook(
                       oWorkbook, oReadWorkbookContext));
        }
        ReadWorkbook
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook
        )
        {
            Debug.Assert(oWorkbook != null);
            AssertValid();

            ReadWorkbookContext oReadWorkbookContext = new ReadWorkbookContext();

            WorkbookReader oWorkbookReader = new WorkbookReader();

            // Convert the workbook contents to a Graph object.

            return(oWorkbookReader.ReadWorkbook(
                       oWorkbook, oReadWorkbookContext));
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
    ReadWorkbook
    (
        Boolean bLayOutGraph
    )
    {
        AssertValid();

        if (oNodeXLControl.IsLayingOutGraph)
        {
            return;
        }

        RemoveSplashScreen();

        if (
            !this.NonEmptyWorkbookRead
            && this.LayoutIsNull
            && !ShowLayoutTypeIsNullNotification()
            )
        {
            return;
        }

        // This is in case another open workbook has modified the user
        // settings.

        GeneralUserSettings oGeneralUserSettings = new GeneralUserSettings();
        GroupUserSettings oGroupUserSettings = new GroupUserSettings();

        ApplyGeneralUserSettings(oGeneralUserSettings);
        ApplyLayoutUserSettings( new LayoutUserSettings() );

        ReadWorkbookContext oReadWorkbookContext = new ReadWorkbookContext();

        oReadWorkbookContext.IgnoreVertexLocations = false;
        oReadWorkbookContext.GraphRectangle = this.GraphRectangle;
        oReadWorkbookContext.FillIDColumns = true;
        oReadWorkbookContext.ReadGroups = oGroupUserSettings.ReadGroups;
        oReadWorkbookContext.ReadEdgeWeights = true;

        oReadWorkbookContext.ReadVertexColorFromGroups =
            oGroupUserSettings.ReadVertexColorFromGroups;

        oReadWorkbookContext.ReadVertexShapeFromGroups =
            oGroupUserSettings.ReadVertexShapeFromGroups;

        oReadWorkbookContext.ReadVertexLabels = m_oRibbon.ReadVertexLabels;
        oReadWorkbookContext.ReadEdgeLabels = m_oRibbon.ReadEdgeLabels;
        oReadWorkbookContext.ReadGroupLabels = m_oRibbon.ReadGroupLabels;
        oReadWorkbookContext.ReadVertexImages = true;

        oReadWorkbookContext.DefaultVertexImageSize =
            oGeneralUserSettings.VertexImageSize;

        oReadWorkbookContext.DefaultVertexShape =
            oGeneralUserSettings.VertexShape;

        // Populate the vertex worksheet.  This isn't strictly necessary, but
        // it does enable the vertex worksheet to be updated when the user
        // edits vertex attributes in the NodeXL graph.  (If the vertex
        // worksheet is missing, vertex attributes can still be edited in the
        // graph; the edits just won't get saved in the workbook.)

        oReadWorkbookContext.PopulateVertexWorksheet = true;

        WorkbookReader oWorkbookReader = new WorkbookReader();

        m_oEdgeRowIDDictionary = null;
        m_oVertexRowIDDictionary = null;

        EnableGraphControls(false);

        try
        {
            // Read the workbook into a Graph object.

            IGraph oGraph = oWorkbookReader.ReadWorkbook(
                m_oWorkbook, oReadWorkbookContext);

            // Save the edge and vertex dictionaries that were created by
            // WorkbookReader.

            m_oEdgeRowIDDictionary = oReadWorkbookContext.EdgeRowIDDictionary;

            m_oVertexRowIDDictionary =
                oReadWorkbookContext.VertexRowIDDictionary;

            // Load the NodeXLControl with the resulting graph.

            oNodeXLControl.Graph = oGraph;

            // Collapse any groups that are supposed to be collapsed.

            CollapseOrExpandGroups(GetGroupNamesToCollapse(oGraph), true,
                false);

            // Enable tooltips in case tooltips were specified in the workbook.

            oNodeXLControl.ShowVertexToolTips = true;

            // If the dynamic filter dialog is open, read the dynamic filter
            // columns it filled in.

            if (m_oDynamicFilterDialog != null)
            {
                ReadDynamicFilterColumns(false);

                DynamicFilterHandler.ReadFilteredAlpha(m_oDynamicFilterDialog,
                    oNodeXLControl, false);
            }

            oNodeXLControl.DrawGraph(bLayOutGraph);

            PerWorkbookSettings oPerWorkbookSettings =
                this.PerWorkbookSettings;

            UpdateAutoFillResultsLegend(oPerWorkbookSettings);
            UpdateDynamicFiltersLegend();
            UpdateAxes(oPerWorkbookSettings);
            UpdateGraphHistory(oPerWorkbookSettings);
        }
        catch (Exception oException)
        {
            // If exceptions aren't caught here, Excel consumes them without
            // indicating that anything is wrong.  This can result in the graph
            // controls remaining disabled, among other problems.

            ErrorUtil.OnException(oException);
        }
        finally
        {
            EnableGraphControls(true);
        }

        // Change the button text to indicate that if any of the buttons is
        // clicked again, the graph will be read again.

        tsbReadWorkbook.Text = msiContextReadWorkbook.Text =
            m_oRibbon.ReadWorkbookButtonText =
            "Refresh Graph";
    }
    ReadWorkbook
    (
        Microsoft.Office.Interop.Excel.Workbook oWorkbook,
        IGraphMetricCalculator2 [] oGraphMetricCalculators
    )
    {
        Debug.Assert(oWorkbook != null);
        Debug.Assert(oGraphMetricCalculators != null);
        AssertValid();

        ReadWorkbookContext oReadWorkbookContext = new ReadWorkbookContext();
        oReadWorkbookContext.FillIDColumns = true;
        oReadWorkbookContext.PopulateVertexWorksheet = true;
        oReadWorkbookContext.ReadGroups = true;

        // Some of the graph metric calculators, such as
        // TopItemsCalculatorBase2, need to rank vertices or edges by values in
        // a specified column.  Make those values available on the graph.

        oReadWorkbookContext.ReadAllEdgeAndVertexColumns = true;

        WorkbookReader oWorkbookReader = new WorkbookReader();

        return ( oWorkbookReader.ReadWorkbook(
            oWorkbook, oReadWorkbookContext) );
    }
    ReadWorkbook
    (
        Microsoft.Office.Interop.Excel.Workbook oWorkbook
    )
    {
        Debug.Assert(oWorkbook != null);
        AssertValid();

        ReadWorkbookContext oReadWorkbookContext = new ReadWorkbookContext();

        WorkbookReader oWorkbookReader = new WorkbookReader();

        // Convert the workbook contents to a Graph object.

        return ( oWorkbookReader.ReadWorkbook(
            oWorkbook, oReadWorkbookContext) );
    }
    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);
    }