Smrf.NodeXL.ExcelTemplate.VertexWorksheetReader.ReadWorksheet C# (CSharp) Method

ReadWorksheet() public method

public ReadWorksheet ( Microsoft workbook, ReadWorkbookContext readWorkbookContext, IGraph graph ) : void
workbook Microsoft
readWorkbookContext ReadWorkbookContext
graph IGraph
return void
    ReadWorksheet
    (
        Microsoft.Office.Interop.Excel.Workbook workbook,
        ReadWorkbookContext readWorkbookContext,
        IGraph graph
    )
    {
        Debug.Assert(workbook != null);
        Debug.Assert(readWorkbookContext != null);
        Debug.Assert(graph != null);
        AssertValid();

        // Attempt to get the optional table that contains vertex data.

        ListObject oVertexTable;

        if (ExcelTableUtil.TryGetTable(workbook, WorksheetNames.Vertices,
            TableNames.Vertices, out oVertexTable) )
        {
            // The code that reads the table can handle hidden rows, but not
            // hidden columns.  Temporarily show all hidden columns in the
            // table.

            ExcelHiddenColumns oHiddenColumns =
                ExcelColumnHider.ShowHiddenColumns(oVertexTable);

            Boolean bLayoutAndZOrderSet;

            try
            {
                ReadVertexTable(oVertexTable, readWorkbookContext, graph,
                    out bLayoutAndZOrderSet);

                RemoveUnwantedIsolates(readWorkbookContext, graph);
            }
            finally
            {
                ExcelColumnHider.RestoreHiddenColumns(oVertexTable,
                    oHiddenColumns);
            }

            if (bLayoutAndZOrderSet)
            {
                // The layout and z-orders were specified for at least one
                // vertex.  The ByMetadataVertexSorter used by
                // SortableLayoutBase and GraphDrawer requires that if an order
                // is set on one vertex, it must be set on all vertices.  This
                // isn't required in the Excel template, though, so set a
                // default order for each vertex that doesn't already specify
                // one.

                SetUnspecifiedVertexLayoutAndZOrders(graph);

                // The layout and z-orders are ignored unless this key is added
                // to the graph.

                graph.SetValue(
                    ReservedMetadataKeys.SortableLayoutAndZOrderSet, null);
            }
        }
    }

Usage Example

コード例 #1
0
ファイル: WorkbookReader.cs プロジェクト: yesbb12/ParallelBFS
        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);
        }
All Usage Examples Of Smrf.NodeXL.ExcelTemplate.VertexWorksheetReader::ReadWorksheet