Exemple #1
0
        TryCreateStackedTable
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            String sWorksheetName,
            GraphMetricColumn oGraphMetricColumn,
            out ListObject oStackedTable
        )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(!String.IsNullOrEmpty(sWorksheetName));
            Debug.Assert(oGraphMetricColumn != null);
            AssertValid();

            oStackedTable = null;
            Worksheet oWorksheet;
            Range     oColumnARange;

            if (
                !ExcelUtil.TryGetOrAddWorksheet(oWorkbook, sWorksheetName,
                                                out oWorksheet)
                ||
                !ExcelUtil.TryGetRange(oWorksheet, "A:A", out oColumnARange)
                )
            {
                return(false);
            }

            try
            {
                // The worksheet can contain multiple top-N-by tables, so we need
                // to find where to put the new table.

                Range oColumn1HeaderCell = GetColumn1HeaderCellForStackedTable(
                    oWorksheet, oColumnARange);

                // Create just the first column.  The table will auto-expand when
                // this class adds the table's other column.
                //
                // (It's assumed here that oGraphMetricColumn represents the
                // table's first column.)

                oColumn1HeaderCell.set_Value(Missing.Value,
                                             oGraphMetricColumn.ColumnName);

                Range oTableRange = oColumn1HeaderCell;
                ExcelUtil.ResizeRange(ref oTableRange, 2, 1);

                oStackedTable = ExcelTableUtil.AddTable(oWorksheet, oTableRange,
                                                        oGraphMetricColumn.TableName, TableStyleNames.NodeXLTable);

                ExcelTableUtil.SetColumnWidth(oColumn1HeaderCell,
                                              oGraphMetricColumn.ColumnWidthChars);
            }
            catch (System.Runtime.InteropServices.COMException)
            {
                return(false);
            }

            return(true);
        }
Exemple #2
0
        TryCreateGroupEdgeTable
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            out ListObject oGroupEdgeTable
        )
        {
            Debug.Assert(oWorkbook != null);
            AssertValid();

            oGroupEdgeTable = null;
            Worksheet oGroupEdgeWorksheet;

            if (!ExcelUtil.TryGetOrAddWorksheet(oWorkbook,
                                                WorksheetNames.GroupEdgeMetrics, out oGroupEdgeWorksheet))
            {
                return(false);
            }

            Range oRange;

            try
            {
                // Create just the first column.  The table will auto-expand when
                // this class adds the table's other columns.

                oRange = ExcelUtil.SetCellStringValue(oGroupEdgeWorksheet, "C1",
                                                      "Graph Metrics");

                ExcelUtil.SetCellStringValue(oGroupEdgeWorksheet, "A2",
                                             GroupEdgeTableColumnNames.Group1Name);

                ExcelUtil.SetRangeStyle(oRange, CellStyleNames.GraphMetricGood);
                oRange.EntireColumn.AutoFit();

                oGroupEdgeTable = ExcelTableUtil.AddTable(oGroupEdgeWorksheet,
                                                          ExcelUtil.GetRange(oGroupEdgeWorksheet, "A2:A3"),
                                                          TableNames.GroupEdgeMetrics, TableStyleNames.NodeXLTable);
            }
            catch (System.Runtime.InteropServices.COMException)
            {
                return(false);
            }

            return(true);
        }
        WriteOverallMetricsToNewWorkbook
        (
            Microsoft.Office.Interop.Excel.Application oApplicationForNewWorkbook,
            IList <OverallMetricsInfo> oOverallMetricsInfos
        )
        {
            Debug.Assert(oApplicationForNewWorkbook != null);
            Debug.Assert(oOverallMetricsInfos != null);
            AssertValid();

            Workbook oNewWorkbook =
                oApplicationForNewWorkbook.Workbooks.Add(Missing.Value);


            Int32 iOverallMetricsInfos = oOverallMetricsInfos.Count;

            // There are 16 overall metrics, plus one extra column for the file
            // name.

            const Int32 Columns = 1 + 16;

            // There is one extra row for the headers.

            Object [,] aoCellValues =
                ExcelUtil.Get2DArray <Object>(1 + iOverallMetricsInfos, Columns);

            String [] asColumnHeaders =
            {
                "File Name",
                OverallMetricNames.Directedness,
                OverallMetricNames.Vertices,
                OverallMetricNames.UniqueEdges,
                OverallMetricNames.EdgesWithDuplicates,
                OverallMetricNames.TotalEdges,
                OverallMetricNames.SelfLoops,
                OverallMetricNames.ReciprocatedVertexPairRatio,
                OverallMetricNames.ReciprocatedEdgeRatio,
                OverallMetricNames.ConnectedComponents,
                OverallMetricNames.SingleVertexConnectedComponents,
                OverallMetricNames.MaximumConnectedComponentVertices,
                OverallMetricNames.MaximumConnectedComponentEdges,
                OverallMetricNames.MaximumGeodesicDistance,
                OverallMetricNames.AverageGeodesicDistance,
                OverallMetricNames.GraphDensity,
                OverallMetricNames.Modularity,
            };

            Debug.Assert(asColumnHeaders.Length == Columns);

            for (Int32 iColumn = 0; iColumn < Columns; iColumn++)
            {
                aoCellValues[1, iColumn + 1] = asColumnHeaders[iColumn];
            }

            for (Int32 i = 0; i < iOverallMetricsInfos; i++)
            {
                OverallMetricsInfo oOverallMetricsInfo = oOverallMetricsInfos[i];

                OverallMetrics oOverallMetrics =
                    oOverallMetricsInfo.OverallMetrics;

                Object [] aoColumnValues =
                {
                    oOverallMetricsInfo.NodeXLWorkbookFileName,
                    oOverallMetrics.Directedness.ToString(),
                    oOverallMetrics.Vertices,
                    oOverallMetrics.UniqueEdges,
                    oOverallMetrics.EdgesWithDuplicates,
                    oOverallMetrics.TotalEdges,
                    oOverallMetrics.SelfLoops,

                    OverallMetricCalculator2.NullableToGraphMetricValue <Double>(
                        oOverallMetrics.ReciprocatedVertexPairRatio),

                    OverallMetricCalculator2.NullableToGraphMetricValue <Double>(
                        oOverallMetrics.ReciprocatedEdgeRatio),

                    oOverallMetrics.ConnectedComponents,
                    oOverallMetrics.SingleVertexConnectedComponents,
                    oOverallMetrics.MaximumConnectedComponentVertices,
                    oOverallMetrics.MaximumConnectedComponentEdges,

                    OverallMetricCalculator2.NullableToGraphMetricValue <Int32>(
                        oOverallMetrics.MaximumGeodesicDistance),

                    OverallMetricCalculator2.NullableToGraphMetricValue <Double>(
                        oOverallMetrics.AverageGeodesicDistance),

                    OverallMetricCalculator2.NullableToGraphMetricValue <Double>(
                        oOverallMetrics.GraphDensity),

                    OverallMetricCalculator2.NullableToGraphMetricValue <Double>(
                        oOverallMetrics.Modularity),
                };

                Debug.Assert(aoColumnValues.Length == Columns);

                for (Int32 iColumn = 0; iColumn < Columns; iColumn++)
                {
                    aoCellValues[i + 2, iColumn + 1] = aoColumnValues[iColumn];
                }
            }

            Worksheet oNewWorksheet = (Worksheet)oNewWorkbook.Worksheets[1];

            // Insert the overall metrics into a table.

            Range oTableRange = ExcelUtil.SetRangeValues(
                (Range)oNewWorksheet.Cells[1, 1], aoCellValues);

            ExcelTableUtil.AddTable(oNewWorksheet, oTableRange, null, null);
        }