ReadWorkbook
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            GraphMetricUserSettings oGraphMetricUserSettings
        )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(oGraphMetricUserSettings != null);
            AssertValid();

            ReadWorkbookContext oReadWorkbookContext = new ReadWorkbookContext();

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

            if ((oGraphMetricUserSettings.GraphMetricsToCalculate &
                 GraphMetrics.GroupMetrics) != 0)
            {
                oReadWorkbookContext.ReadGroups        = true;
                oReadWorkbookContext.SaveGroupVertices = true;
            }

            WorkbookReader oWorkbookReader = new WorkbookReader();

            return(oWorkbookReader.ReadWorkbook(
                       oWorkbook, oReadWorkbookContext));
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
0
        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));
        }
        //*************************************************************************
        //  Method: ReadWorkbook()
        //
        /// <summary>
        /// Reads the workbook contents into a NodeXL graph.
        /// </summary>
        ///
        /// <param name="oWorkbook">
        /// Workbook containing the graph contents.
        /// </param>
        ///
        /// <param name="oGraphMetricUserSettings">
        /// User settings for calculating graph metrics.
        /// </param>
        ///
        /// <returns>
        /// The <see cref="IGraph" /> read from the workbook.
        /// </returns>
        ///
        /// <remarks>
        /// If <paramref name="oWorkbook" /> contains valid graph data, a new <see
        /// cref="IGraph" /> is created from the workbook contents and returned.
        /// Otherwise, a <see cref="WorkbookFormatException" /> is thrown.
        /// </remarks>
        //*************************************************************************
        protected IGraph ReadWorkbook(
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            GraphMetricUserSettings oGraphMetricUserSettings
            )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(oGraphMetricUserSettings != null);
            AssertValid();

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

            if ( (oGraphMetricUserSettings.GraphMetricsToCalculate &
            GraphMetrics.GroupMetrics) != 0)
            {
            oReadWorkbookContext.ReadGroups = true;
            oReadWorkbookContext.SaveGroupVertices = true;
            }

            WorkbookReader oWorkbookReader = new WorkbookReader();

            return ( oWorkbookReader.ReadWorkbook(
            oWorkbook, oReadWorkbookContext) );
        }
Ejemplo n.º 5
0
        //*************************************************************************
        //  Method: ReadWorkbook()
        //
        /// <summary>
        /// Transfers data from the workbook to the NodeXLControl and optionally
        /// lays out the graph.
        /// </summary>
        ///
        /// <param name="bLayOutGraph">
        /// true to lay out the graph.
        /// </param>
        //*************************************************************************
        protected void ReadWorkbook(
            Boolean bLayOutGraph
            )
        {
            AssertValid();

            if (oNodeXLControl.IsLayingOutGraph)
            {
            return;
            }

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

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

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

            ReadWorkbookContext oReadWorkbookContext = new ReadWorkbookContext();

            oReadWorkbookContext.IgnoreVertexLocations = false;
            oReadWorkbookContext.GraphRectangle = this.GraphRectangle;
            oReadWorkbookContext.FillIDColumns = true;
            oReadWorkbookContext.ReadGroups = m_oRibbon.ReadGroups;
            oReadWorkbookContext.ReadVertexLabels = m_oRibbon.ReadVertexLabels;
            oReadWorkbookContext.ReadEdgeLabels = m_oRibbon.ReadEdgeLabels;
            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 only if tooltips were specified in the workbook.

            oNodeXLControl.ShowVertexToolTips = oGraph.ContainsKey(
                ReservedMetadataKeys.ToolTipSet);

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

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

            oNodeXLControl.DrawGraph(bLayOutGraph);

            PerWorkbookSettings oPerWorkbookSettings =
                this.PerWorkbookSettings;

            UpdateAutoFillResultsLegend(oPerWorkbookSettings);
            UpdateDynamicFiltersLegend();
            UpdateAxes(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";
        }
        //*************************************************************************
        //  Method: ReadWorkbook()
        //
        /// <summary>
        /// Reads a workbook into a new graph.
        /// </summary>
        ///
        /// <param name="oWorkbook">
        /// The workbook to read.
        /// </param>
        ///
        /// <returns>
        /// The new graph.
        /// </returns>
        //*************************************************************************
        protected IGraph 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.º 7
0
        //*************************************************************************
        //  Method: ExportToFile()
        //
        /// <summary>
        /// Merges duplicate edges and exports the edge and vertex tables to a file
        /// using a provided dialog.
        /// </summary>
        ///
        /// <param name="oReadWorkbookContext">
        /// Provides access to objects needed for converting an Excel workbook to a
        /// NodeXL graph.
        /// </param>
        ///
        /// <param name="oSaveGraphFileDialog">
        /// The dialog to use to save the graph.
        /// </param>
        //*************************************************************************
        private void ExportToFile(
            ReadWorkbookContext oReadWorkbookContext,
            SaveGraphFileDialog oSaveGraphFileDialog
            )
        {
            Debug.Assert(oReadWorkbookContext != null);
            Debug.Assert(oSaveGraphFileDialog != null);
            AssertValid();

            WorkbookReader oWorkbookReader = new WorkbookReader();

            ShowWaitCursor = true;
            this.ScreenUpdating = false;

            try
            {
            ( new DuplicateEdgeMerger() ).MergeDuplicateEdges(
                this.InnerObject);

            this.ScreenUpdating = true;

            // Read the workbook and let the user save it.

            IGraph oGraph = oWorkbookReader.ReadWorkbook(
                this.InnerObject, oReadWorkbookContext);

            oSaveGraphFileDialog.ShowDialogAndSaveGraph(oGraph);
            }
            catch (Exception oException)
            {
            this.ScreenUpdating = true;
            ErrorUtil.OnException(oException);
            }
            finally
            {
            this.ScreenUpdating = true;
            ShowWaitCursor = false;
            }
        }