MergeDuplicateEdges ( Microsoft.Office.Interop.Excel.Workbook workbook, Boolean countDuplicateEdges, Boolean deleteDuplicateEdges, String thirdColumnNameForDuplicateDetection ) { Debug.Assert(workbook != null); AssertValid(); ListObject oEdgeTable; if (TryGetEdgeTable(workbook, out oEdgeTable)) { ExcelUtil.ActivateWorksheet(oEdgeTable); // Clear AutoFiltering, which would make this code much more // complicated. ExcelTableUtil.ClearTableAutoFilters(oEdgeTable); Boolean bGraphIsDirected; Range oVertex1NameData, oVertex2NameData; Object [,] aoVertex1NameValues, aoVertex2NameValues, aoThirdColumnValues; if (TryGetInformationFromEdgeTable(workbook, oEdgeTable, thirdColumnNameForDuplicateDetection, out bGraphIsDirected, out oVertex1NameData, out aoVertex1NameValues, out oVertex2NameData, out aoVertex2NameValues, out aoThirdColumnValues )) { if (countDuplicateEdges) { CountDuplicateEdges(oEdgeTable, aoVertex1NameValues, aoVertex2NameValues, aoThirdColumnValues, bGraphIsDirected); } if (deleteDuplicateEdges) { DeleteDuplicateEdges(oEdgeTable, aoVertex1NameValues, aoVertex2NameValues, aoThirdColumnValues, bGraphIsDirected); } } } }
WriteGraphMetricColumnsToWorkbook ( GraphMetricColumn [] graphMetricColumns, Microsoft.Office.Interop.Excel.Workbook workbook ) { Debug.Assert(graphMetricColumns != null); Debug.Assert(workbook != null); AssertValid(); // Clear any worksheets that must be cleared before anything else is // done. ClearWorksheets(graphMetricColumns, workbook); // (Note: Don't sort grapMetricColumns by worksheet name/table name in // an effort to minimize worksheet switches in the code below. That // would interfere with the column order specified by the // IGraphMetricCalculator2 implementations. // Create a dictionary of tables that have been written to. The key is // the worksheet name + table name, and the value is a WrittenTableInfo // object that contains information about the table. Dictionary <String, WrittenTableInfo> oWrittenTables = new Dictionary <String, WrittenTableInfo>(); // Loop through the columns. String sCurrentWorksheetPlusTable = String.Empty; ListObject oTable = null; foreach (GraphMetricColumn oGraphMetricColumn in graphMetricColumns) { String sThisWorksheetPlusTable = oGraphMetricColumn.WorksheetName + oGraphMetricColumn.TableName; if (sThisWorksheetPlusTable != sCurrentWorksheetPlusTable) { // This is a different table. Get its ListObject. if (!TryGetTable(workbook, oGraphMetricColumn, out oTable)) { continue; } sCurrentWorksheetPlusTable = sThisWorksheetPlusTable; } WrittenTableInfo oWrittenTableInfo; if (!oWrittenTables.TryGetValue(sThisWorksheetPlusTable, out oWrittenTableInfo)) { // Show all the table's columns. If a graph metric column // isn't visible, it can't be written to. ExcelHiddenColumns oExcelHiddenColumns = ExcelColumnHider.ShowHiddenColumns(oTable); oWrittenTableInfo = new WrittenTableInfo(); oWrittenTableInfo.Table = oTable; oWrittenTableInfo.HiddenColumns = oExcelHiddenColumns; oWrittenTableInfo.Cleared = false; oWrittenTables.Add(sThisWorksheetPlusTable, oWrittenTableInfo); } // Apparent Excel bug: Adding a column when the header row is not // the default row height increases the header row height. Work // around this by saving the height and restoring it below. Double dHeaderRowHeight = (Double)oTable.HeaderRowRange.RowHeight; // Write the column. Debug.Assert(oTable != null); if (oGraphMetricColumn is GraphMetricColumnWithID) { WriteGraphMetricColumnWithIDToWorkbook( (GraphMetricColumnWithID)oGraphMetricColumn, oTable); } else if (oGraphMetricColumn is GraphMetricColumnOrdered) { if (!oWrittenTableInfo.Cleared) { // GraphMetricColumnOrdered columns require that the table // be cleared before any graph metric values are written to // it. ExcelTableUtil.ClearTable(oTable); oWrittenTableInfo.Cleared = true; // Clear AutoFiltering, which interferes with writing an // ordered list to the column. ExcelTableUtil.ClearTableAutoFilters(oTable); } WriteGraphMetricColumnOrderedToWorkbook( (GraphMetricColumnOrdered)oGraphMetricColumn, oTable); } else { Debug.Assert(false); } oTable.HeaderRowRange.RowHeight = dHeaderRowHeight; } // Restore any hidden columns in the tables that were written to. foreach (KeyValuePair <String, WrittenTableInfo> oKeyValuePair in oWrittenTables) { WrittenTableInfo oWrittenTableInfo = oKeyValuePair.Value; ExcelColumnHider.RestoreHiddenColumns(oWrittenTableInfo.Table, oWrittenTableInfo.HiddenColumns); } }