SetVisualAttribute ( RunSetVisualAttributeCommandEventArgs e, Range selectedRange, String colorColumnName, String alphaColumnName ) { Debug.Assert(e != null); Debug.Assert(selectedRange != null); Debug.Assert(ExcelUtil.WorksheetIsActive(m_oWorksheet.InnerObject)); AssertValid(); if (e.VisualAttribute == VisualAttributes.Color && colorColumnName != null) { String sColor; // Get a color from the user. if (NodeXLWorkbookUtil.TryGetColor(out sColor)) { ExcelTableUtil.SetVisibleSelectedTableColumnData( m_oTable.InnerObject, selectedRange, colorColumnName, sColor); e.VisualAttributeSet = true; } } }
GetVertexColumnData ( ListObject oDestinationEdgeTable, Boolean bGetVertex1 ) { Debug.Assert(oDestinationEdgeTable != null); AssertValid(); Range oVertexColumnData; if ( !ExcelTableUtil.TryGetTableColumnData(oDestinationEdgeTable, bGetVertex1 ? EdgeTableColumnNames.Vertex1Name : EdgeTableColumnNames.Vertex2Name, out oVertexColumnData) ) { OnInvalidSourceWorkbook( "One of the vertex columns is missing from the NodeXL" + " workbook." ); } return(oVertexColumnData); }
TryGetNamesAndValues ( Microsoft.Office.Interop.Excel.Workbook oWorkbook, out Object [,] aoNames, out Object [,] aoValues ) { Debug.Assert(oWorkbook != null); AssertValid(); aoNames = aoValues = null; ListObject oOverallMetricsTable; Range oRange; return( ExcelTableUtil.TryGetTable(oWorkbook, WorksheetNames.OverallMetrics, TableNames.OverallMetrics, out oOverallMetricsTable) && ExcelTableUtil.TryGetTableColumnDataAndValues( oOverallMetricsTable, OverallMetricsTableColumnNames.Name, out oRange, out aoNames) && ExcelTableUtil.TryGetTableColumnDataAndValues( oOverallMetricsTable, OverallMetricsTableColumnNames.Value, out oRange, out aoValues) ); }
//************************************************************************* // Constructor: GroupByVertexAttributeDialog() // /// <overloads> /// Initializes a new instance of the <see /// cref="GroupByVertexAttributeDialog" /> class. /// </overloads> /// /// <param name="workbook"> /// Workbook containing the graph contents. /// </param> //************************************************************************* public GroupByVertexAttributeDialog ( Microsoft.Office.Interop.Excel.Workbook workbook ) { InitializeComponent(); m_oWorkbook = workbook; // Instantiate an object that saves and retrieves the user settings for // this dialog. Note that the object automatically saves the settings // when the form closes. m_oGroupByVertexAttributeDialogUserSettings = new GroupByVertexAttributeDialogUserSettings(this); if (ExcelTableUtil.TryGetTable(m_oWorkbook, WorksheetNames.Vertices, TableNames.Vertices, out m_oVertexTable)) { cbxVertexColumnName.PopulateWithTableColumnNames(m_oVertexTable); } cbxVertexColumnFormat.PopulateWithObjectsAndText( ExcelColumnFormat.Other, "Categories", ExcelColumnFormat.Number, "Numbers", ExcelColumnFormat.Date, "Dates", ExcelColumnFormat.Time, "Times", ExcelColumnFormat.DateAndTime, "Dates with times" ); DoDataExchange(false); AssertValid(); }
AddCollapsedGroupAttributes ( Microsoft.Office.Interop.Excel.Workbook workbook, ReadWorkbookContext readWorkbookContext, IGraph graph ) { Debug.Assert(workbook != null); Debug.Assert(readWorkbookContext != null); Debug.Assert(graph != null); GroupInfo[] aoGroups; ListObject oEdgeTable, oVertexTable; if ( GroupUtil.TryGetGroups(graph, out aoGroups) && ExcelTableUtil.TryGetTable(workbook, WorksheetNames.Edges, TableNames.Edges, out oEdgeTable) && ExcelTableUtil.TryGetTable(workbook, WorksheetNames.Vertices, TableNames.Vertices, out oVertexTable) ) { AddCollapsedGroupAttributesInternal(workbook, readWorkbookContext, oEdgeTable, oVertexTable, aoGroups); } }
TryCollapseOrExpandSelectedGroups ( Microsoft.Office.Interop.Excel.Workbook oWorkbook, Boolean bCollapse ) { Debug.Assert(oWorkbook != null); ListObject oGroupTable; Range oSelectedTableRange; if (ExcelTableUtil.TryGetSelectedTableRange(oWorkbook, WorksheetNames.Groups, TableNames.Groups, out oGroupTable, out oSelectedTableRange)) { // Store the new collapsed state in the group table. ExcelTableUtil.SetVisibleSelectedTableColumnData(oGroupTable, oSelectedTableRange, GroupTableColumnNames.Collapsed, (new BooleanConverter()).GraphToWorkbook(bCollapse)); return(true); } return(false); }
cbxVertexColumnName_SelectedIndexChanged ( object sender, EventArgs e ) { AssertValid(); String sVertexColumnName = cbxVertexColumnName.Text; ListColumn oVertexColumn; if ( String.IsNullOrEmpty(sVertexColumnName) || m_oVertexTable == null || !ExcelTableUtil.TryGetTableColumn(m_oVertexTable, sVertexColumnName, out oVertexColumn) ) { return; } cbxVertexColumnFormat.SelectedValue = ExcelTableUtil.GetTableColumnFormat(oVertexColumn); EnableControls(); }
GetOrAddTableColumn ( ListColumn oSourceColumn, ListObject oNewTable ) { Debug.Assert(oSourceColumn != null); Debug.Assert(oNewTable != null); AssertValid(); String sColumnName = oSourceColumn.Name; Range oSourceColumnData = oSourceColumn.DataBodyRange; Debug.Assert(oSourceColumnData != null); ListColumn oNewColumn; if (!ExcelTableUtil.TryGetOrAddTableColumn(oNewTable, sColumnName, (Double)oSourceColumnData.ColumnWidth, null, out oNewColumn)) { throw new ExportWorkbookException( "A column couldn't be added to the new workbook." ); } Range oNewColumnData = oNewColumn.DataBodyRange; Debug.Assert(oNewColumnData != null); oNewColumnData.NumberFormat = oSourceColumnData.NumberFormat; return(oNewColumnData); }
ClearAllNodeXLTables ( Microsoft.Office.Interop.Excel.Workbook workbook ) { Debug.Assert(workbook != null); SubgraphImageColumnPopulator.DeleteSubgraphImages(workbook); ExcelTableUtil.ClearTables(workbook, WorksheetNames.Edges, TableNames.Edges, WorksheetNames.Vertices, TableNames.Vertices, WorksheetNames.OverallMetrics, TableNames.OverallMetrics, WorksheetNames.OverallMetrics, TableNames.OverallReadabilityMetrics, WorksheetNames.Miscellaneous, TableNames.DynamicFilterSettings ); ClearGroupTables(workbook); foreach (String sWorksheetName in new String [] { WorksheetNames.TopNByMetrics, WorksheetNames.TwitterSearchNetworkTopItems, WorksheetNames.WordCounts, WorksheetNames.WordPairCounts, }) { ExcelUtil.TryClearWorksheet(workbook, sWorksheetName); } (new PerWorkbookSettings(workbook)).OnWorkbookTablesCleared(); }
GetTableColumnIndex ( ListObject oTable, String sColumnName, Boolean bColumnIsRequired ) { Debug.Assert(oTable != null); Debug.Assert(!String.IsNullOrEmpty(sColumnName)); AssertValid(); ListColumn oColumn; if (ExcelTableUtil.TryGetTableColumn(oTable, sColumnName, out oColumn)) { return(oColumn.Index); } if (bColumnIsRequired) { OnWorkbookFormatError(String.Format( "The table named \"{0}\" must have a column named \"{1}.\"" + "\r\n\r\n{2}" , oTable.Name, sColumnName, ErrorUtil.GetTemplateMessage() )); } return(NoSuchColumn); }
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); }
TryGetRequiredColumnWithIDInformation ( GraphMetricColumnWithID oGraphMetricColumnWithID, ListObject oTable, out Range oVisibleColumnData, out Range oIDColumnData ) { Debug.Assert(oGraphMetricColumnWithID != null); Debug.Assert(oTable != null); AssertValid(); oVisibleColumnData = null; oIDColumnData = null; // Get the specified column. if (!TryGetRequiredColumnInformation(oGraphMetricColumnWithID, oTable, out oVisibleColumnData)) { return(false); } // Get the ID column. if (!ExcelTableUtil.TryGetTableColumnData(oTable, CommonTableColumnNames.ID, out oIDColumnData)) { return(false); } return(true); }
TryGetIDAndDynamicFilterValues ( Microsoft.Office.Interop.Excel.Workbook oWorkbook, String sWorksheetName, String sTableName, out Object [,] oIDColumnValues, out Object [,] oDynamicFilterColumnValues ) { Debug.Assert(oWorkbook != null); Debug.Assert(!String.IsNullOrEmpty(sWorksheetName)); Debug.Assert(!String.IsNullOrEmpty(sTableName)); oIDColumnValues = oDynamicFilterColumnValues = null; ListObject oTable; Range oIDColumnData, oDynamicFilterColumnData; return( ExcelTableUtil.TryGetTable(oWorkbook, sWorksheetName, sTableName, out oTable) && ExcelTableUtil.TryGetTableColumnDataAndValues(oTable, CommonTableColumnNames.ID, out oIDColumnData, out oIDColumnValues) && ExcelTableUtil.TryGetTableColumnDataAndValues(oTable, CommonTableColumnNames.DynamicFilter, out oDynamicFilterColumnData, out oDynamicFilterColumnValues) ); }
//************************************************************************* // Constructor: AddSelectedVerticesToGroupDialog() // /// <summary> /// Initializes a new instance of the <see /// cref="AddSelectedVerticesToGroupDialog" /> class. /// </summary> /// /// <param name="workbook"> /// Workbook containing the graph data. /// </param> //************************************************************************* public AddSelectedVerticesToGroupDialog ( Microsoft.Office.Interop.Excel.Workbook workbook ) { Debug.Assert(workbook != null); m_oWorkbook = workbook; m_sGroupName = null; m_bIsNewGroup = false; InitializeComponent(); // Instantiate an object that saves and retrieves the user settings for // this dialog. Note that the object automatically saves the settings // when the form closes. m_oAddSelectedVerticesToGroupDialogUserSettings = new AddSelectedVerticesToGroupDialogUserSettings(this); ICollection <String> oUniqueGroupNames; if (ExcelTableUtil.TryGetUniqueTableColumnStringValues(m_oWorkbook, WorksheetNames.Groups, TableNames.Groups, GroupTableColumnNames.Name, out oUniqueGroupNames)) { cbxGroupName.DataSource = oUniqueGroupNames.ToArray(); } DoDataExchange(false); AssertValid(); }
ManageTextWrapBeforeImport ( IGraph sourceGraph, Microsoft.Office.Interop.Excel.Workbook destinationNodeXLWorkbook, Boolean notifyUser ) { Debug.Assert(sourceGraph != null); Debug.Assert(destinationNodeXLWorkbook != null); if (sourceGraph.Edges.Count > RowThreshold || sourceGraph.Vertices.Count > RowThreshold) { if (notifyUser && !NotifyUser()) { return(false); } ExcelTableUtil.SetTableWrapText(destinationNodeXLWorkbook, WorksheetNames.Edges, TableNames.Edges, false); ExcelTableUtil.SetTableWrapText(destinationNodeXLWorkbook, WorksheetNames.Vertices, TableNames.Vertices, false); } return(true); }
TryGetSubgraphImageColumnData ( ListObject oVertexTable, out Range oSubgraphImageColumnData ) { Debug.Assert(oVertexTable != null); oSubgraphImageColumnData = null; ListColumn oSubgraphImageColumn; if ( ExcelTableUtil.TryGetOrInsertTableColumn(oVertexTable, VertexTableColumnNames.SubgraphImage, OneBasedSubgraphImageColumnIndex, SubgraphImageColumnWidthChars, null, out oSubgraphImageColumn) && ExcelTableUtil.TryGetTableColumnData(oSubgraphImageColumn, out oSubgraphImageColumnData) ) { ShiftColumnGroupNames(oVertexTable); return(true); } return(false); }
CopyTableToNewNodeXLWorkbook ( String sWorksheetName, String sTableName, String sTemplatePath, ref Workbook oNewNodeXLWorkbook ) { Debug.Assert(!String.IsNullOrEmpty(sWorksheetName)); Debug.Assert(!String.IsNullOrEmpty(sTableName)); Debug.Assert(!String.IsNullOrEmpty(sTemplatePath)); AssertValid(); ListObject oTable; Range oSelectedTableRange; if ( !ExcelTableUtil.TryGetSelectedTableRange(m_oWorkbookToExport, sWorksheetName, sTableName, out oTable, out oSelectedTableRange) || ExcelTableUtil.VisibleTableRangeIsEmpty(oTable) ) { return; } Range oVisibleSelectedTableRange; // CopyRowsToNewNodeXLWorkbook() can handle hidden rows, but not hidden // columns. Temporarily show all hidden columns in the table. ExcelHiddenColumns oHiddenColumns = ExcelColumnHider.ShowHiddenColumns(oTable); try { if (ExcelUtil.TryGetVisibleRange(oSelectedTableRange, out oVisibleSelectedTableRange)) { // Create the new workbook if necessary and copy the table's // selected rows to it. if (oNewNodeXLWorkbook == null) { oNewNodeXLWorkbook = m_oWorkbookToExport.Application.Workbooks.Add( sTemplatePath); } CopyRowsToNewNodeXLWorkbook(oTable, oVisibleSelectedTableRange, oNewNodeXLWorkbook); } } finally { ExcelColumnHider.RestoreHiddenColumns(oTable, oHiddenColumns); } }
TryGetValuesInAllRows <TValue> ( String sColumnName, ExcelUtil.TryGetValueFromCell <TValue> oTryGetValueFromCell, out Dictionary <TValue, Int32> oValueDictionary ) { Debug.Assert(!String.IsNullOrEmpty(sColumnName)); Debug.Assert(oTryGetValueFromCell != null); AssertValid(); oValueDictionary = null; if (!TableExists) { return(false); } Range oDataBodyRange = m_oTable.DataBodyRange; if (oDataBodyRange == null) { return(false); } Range oColumnData; Object [,] aoColumnValues; // Get the values in the column. This includes hidden rows but // excludes the header row. if (!ExcelTableUtil.TryGetTableColumnDataAndValues( m_oTable.InnerObject, sColumnName, out oColumnData, out aoColumnValues)) { return(false); } oValueDictionary = new Dictionary <TValue, Int32>(); Int32 iDataBodyRangeRow = oDataBodyRange.Row; Int32 iRows = oColumnData.Rows.Count; for (Int32 iRowOneBased = 1; iRowOneBased <= iRows; iRowOneBased++) { TValue tValue; if (!oTryGetValueFromCell(aoColumnValues, iRowOneBased, 1, out tValue)) { continue; } oValueDictionary[tValue] = iRowOneBased + iDataBodyRangeRow - 1; } return(true); }
GetTableColumnNames ( Microsoft.Office.Interop.Excel.ListObject table ) { return(ExcelTableUtil.GetTableColumnNames(table, TableColumnNamesToExclude, ExcelTableUtil.NoColumnNames)); }
ReadEdgeTable ( ListObject oEdgeTable, HashSet <String> oUniqueVertexNames ) { Debug.Assert(oEdgeTable != null); Debug.Assert(oUniqueVertexNames != null); Debug.Assert(oUniqueVertexNames.Count == 0); AssertValid(); // Get the vertex name column ranges. Range oVertex1NameRange, oVertex2NameRange; if (!ExcelTableUtil.TryGetTableColumnData(oEdgeTable, EdgeTableColumnNames.Vertex1Name, out oVertex1NameRange) || !ExcelTableUtil.TryGetTableColumnData(oEdgeTable, EdgeTableColumnNames.Vertex2Name, out oVertex2NameRange) ) { return; } Int32 iRows = oVertex1NameRange.Rows.Count; Debug.Assert(oVertex2NameRange.Rows.Count == iRows); // Read the vertex names all at once. Object [,] aoVertex1NameValues = ExcelUtil.GetRangeValues(oVertex1NameRange); Object [,] aoVertex2NameValues = ExcelUtil.GetRangeValues(oVertex2NameRange); // Loop through the edges. for (Int32 iRowOneBased = 1; iRowOneBased <= iRows; iRowOneBased++) { // Get the vertex names and add them to the HashSet. String sVertex1Name, sVertex2Name; if (ExcelUtil.TryGetNonEmptyStringFromCell(aoVertex1NameValues, iRowOneBased, 1, out sVertex1Name)) { oUniqueVertexNames.Add(sVertex1Name); } if (ExcelUtil.TryGetNonEmptyStringFromCell(aoVertex2NameValues, iRowOneBased, 1, out sVertex2Name)) { oUniqueVertexNames.Add(sVertex2Name); } } }
GetRequiredTables ( Microsoft.Office.Interop.Excel.Workbook oWorkbook, out ListObject oEdgeTable, out ListObject oVertexTable ) { Debug.Assert(oWorkbook != null); AssertValid(); // Get the required table that contains edge data. GetEdgeTable() // checks for the required vertex name columns. EdgeWorksheetReader oEdgeWorksheetReader = new EdgeWorksheetReader(); oEdgeTable = oEdgeWorksheetReader.GetEdgeTable(oWorkbook); // Normally, the vertex table isn't required, but to avoid having to // create the table in code if it's missing, require it here. if (ExcelTableUtil.TryGetTable(oWorkbook, WorksheetNames.Vertices, TableNames.Vertices, out oVertexTable)) { // Make sure the vertex name column exists. ListColumn oColumn; if (!ExcelTableUtil.TryGetTableColumn(oVertexTable, VertexTableColumnNames.VertexName, out oColumn)) { oVertexTable = null; } } else { oVertexTable = null; } if (oVertexTable == null) { throw new WorkbookFormatException(String.Format( "To use this feature, there must be a worksheet named \"{0}\"" + " that contains a table named \"{1}\", and that table must" + " contain a column named \"{2}\"." + "\r\n\r\n" + "{3}" , WorksheetNames.Vertices, TableNames.Vertices, VertexTableColumnNames.VertexName, ErrorUtil.GetTemplateMessage() )); } }
SetVisualAttribute ( RunSetVisualAttributeCommandEventArgs e ) { Debug.Assert(e != null); AssertValid(); Microsoft.Office.Interop.Excel.Range oSelectedRange; if (e.VisualAttributeSet || !m_oSheets1And2Helper.TryGetSelectedRange(out oSelectedRange)) { return; } // See if the specified attribute is set by the helper class. m_oSheets1And2Helper.SetVisualAttribute(e, oSelectedRange, EdgeTableColumnNames.Color, CommonTableColumnNames.Alpha); if (e.VisualAttributeSet) { return; } if (e.VisualAttribute == VisualAttributes.EdgeWidth) { EdgeWidthDialog oEdgeWidthDialog = new EdgeWidthDialog(); if (oEdgeWidthDialog.ShowDialog() == DialogResult.OK) { ExcelTableUtil.SetVisibleSelectedTableColumnData( this.Edges.InnerObject, oSelectedRange, EdgeTableColumnNames.Width, oEdgeWidthDialog.EdgeWidth); e.VisualAttributeSet = true; } } else if (e.VisualAttribute == VisualAttributes.EdgeVisibility) { Debug.Assert(e.AttributeValue is EdgeWorksheetReader.Visibility); ExcelTableUtil.SetVisibleSelectedTableColumnData( this.Edges.InnerObject, oSelectedRange, CommonTableColumnNames.Visibility, (new EdgeVisibilityConverter()).GraphToWorkbook( (EdgeWorksheetReader.Visibility)e.AttributeValue) ); e.VisualAttributeSet = true; } }
MarkRowsForDeletion ( ListObject oEdgeTable, Object [,] aoVertex1NameValues, Object [,] aoVertex2NameValues, Object [,] aoThirdColumnValues, Boolean bGraphIsDirected, out ListColumn oDeleteIfEmptyColumn, out Range oDeleteIfEmptyData, out Object [,] aoDeleteIfEmptyValues ) { Debug.Assert(oEdgeTable != null); Debug.Assert(aoVertex1NameValues != null); Debug.Assert(aoVertex2NameValues != null); AssertValid(); HashSet <String> oUniqueEdgeKeys = new HashSet <String>(); if (!ExcelTableUtil.TryGetOrAddTableColumn(oEdgeTable, DeleteIfEmptyColumnName, ExcelTableUtil.AutoColumnWidth, null, out oDeleteIfEmptyColumn, out oDeleteIfEmptyData, out aoDeleteIfEmptyValues)) { throw new InvalidOperationException( "Can't add marked for deletion column."); } Int32 iRows = GetRowCount(aoVertex1NameValues); for (Int32 iRowOneBased = 1; iRowOneBased <= iRows; iRowOneBased++) { String sEdgeKey; Object oDeleteIfEmpty = 1; if ( TryGetEdgeKey(iRowOneBased, aoVertex1NameValues, aoVertex2NameValues, aoThirdColumnValues, bGraphIsDirected, out sEdgeKey) && !oUniqueEdgeKeys.Add(sEdgeKey) ) { // This is a duplicate that is not the first instance. It // should be deleted. oDeleteIfEmpty = null; } aoDeleteIfEmptyValues[iRowOneBased, 1] = oDeleteIfEmpty; } oDeleteIfEmptyData.set_Value(Missing.Value, aoDeleteIfEmptyValues); }
TryGetPerWorkbookSettingsTable ( out ListObject oPerWorkbookSettingsTable ) { AssertValid(); return(ExcelTableUtil.TryGetTable(m_oWorkbook, WorksheetNames.Miscellaneous, TableNames.PerWorkbookSettings, out oPerWorkbookSettingsTable)); }
SetVertexAttributesForAllGroups ( ListObject oGroupTable ) { Debug.Assert(oGroupTable != null); Range oVertexColorRange, oVertexShapeRange; Object [,] aoVertexColorValues, aoVertexShapeValues; if ( !ExcelTableUtil.TryGetTableColumnDataAndValues(oGroupTable, GroupTableColumnNames.VertexShape, out oVertexShapeRange, out aoVertexShapeValues) || !ExcelTableUtil.TryGetTableColumnDataAndValues(oGroupTable, GroupTableColumnNames.VertexColor, out oVertexColorRange, out aoVertexColorValues) ) { return; } Int32 iGroups = aoVertexShapeValues.GetUpperBound(0); Debug.Assert(aoVertexColorValues.GetUpperBound(0) == iGroups); ColorConverter2 oColorConverter2 = new ColorConverter2(); VertexShapeConverter oVertexShapeConverter = new VertexShapeConverter(); for (Int32 i = 0; i < iGroups; i++) { Color oColor; VertexShape eShape; GetVertexAttributes(i, iGroups, out oColor, out eShape); // Write the color in a format that is understood by // ColorConverter2.WorkbookToGraph(), which is what // WorksheetReaderBase uses. aoVertexColorValues[i + 1, 1] = oColorConverter2.GraphToWorkbook(oColor); aoVertexShapeValues[i + 1, 1] = oVertexShapeConverter.GraphToWorkbook(eShape); } oVertexColorRange.set_Value(Missing.Value, aoVertexColorValues); oVertexShapeRange.set_Value(Missing.Value, aoVertexShapeValues); }
GetEdgeTable ( Microsoft.Office.Interop.Excel.Workbook workbook ) { Debug.Assert(workbook != null); AssertValid(); // Get the worksheet that contains edge data. Worksheet oEdgeWorksheet; if (!ExcelUtil.TryGetWorksheet(workbook, WorksheetNames.Edges, out oEdgeWorksheet)) { OnWorkbookFormatError(String.Format( "The workbook must contain a worksheet named \"{0}\" that" + " contains edge data.\r\n\r\n{1}" , WorksheetNames.Edges, ErrorUtil.GetTemplateMessage() )); } // Get the table (ListObject) that contains edge data. ListObject oEdgeTable; if (!ExcelTableUtil.TryGetTable(oEdgeWorksheet, TableNames.Edges, out oEdgeTable)) { OnWorkbookFormatError(String.Format( "The worksheet named \"{0}\" must have a table named \"{1}\"" + " that contains edge data.\r\n\r\n{2}" , WorksheetNames.Edges, TableNames.Edges, ErrorUtil.GetTemplateMessage() )); } // Make sure the vertex name columns exist. GetTableColumnIndex(oEdgeTable, EdgeTableColumnNames.Vertex1Name, true); GetTableColumnIndex(oEdgeTable, EdgeTableColumnNames.Vertex2Name, true); return(oEdgeTable); }
PopulateEdgeTableWithParticipantPairs ( ListObject edgeTable, ParticipantPair [] participantPairs, Int32 edgeTableRowOffset ) { Debug.Assert(edgeTable != null); Debug.Assert(participantPairs != null); Debug.Assert(edgeTableRowOffset >= 0); Int32 iParticipantPairs = participantPairs.Length; if (iParticipantPairs == 0) { return; } // Create and populate arrays of vertex names. Object [,] aoVertex1Names = new Object [iParticipantPairs, 1]; Object [,] aoVertex2Names = new Object [iParticipantPairs, 1]; for (Int32 i = 0; i < iParticipantPairs; i++) { ParticipantPair oParticipantPair = participantPairs[i]; aoVertex1Names[i, 0] = oParticipantPair.Participant1; aoVertex2Names[i, 0] = oParticipantPair.Participant2; } // Write the arrays to the edge table. Range oVertexColumnData; foreach (String sColumnName in new String [] { EdgeTableColumnNames.Vertex1Name, EdgeTableColumnNames.Vertex2Name }) { if (ExcelTableUtil.TryGetTableColumnData(edgeTable, sColumnName, out oVertexColumnData)) { ExcelUtil.OffsetRange(ref oVertexColumnData, edgeTableRowOffset, 0); ExcelUtil.SetRangeValues(oVertexColumnData, sColumnName == EdgeTableColumnNames.Vertex1Name ? aoVertex1Names : aoVertex2Names, true); } } }
TrySelectAllGroups ( Microsoft.Office.Interop.Excel.Workbook oWorkbook ) { Debug.Assert(oWorkbook != null); ExcelTableUtil.SelectAllTableRows(oWorkbook, WorksheetNames.Groups, TableNames.Groups); return(true); }
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); } } } }
ClearGroupTables ( Microsoft.Office.Interop.Excel.Workbook workbook ) { Debug.Assert(workbook != null); ExcelTableUtil.ClearTables(workbook, WorksheetNames.Groups, TableNames.Groups, WorksheetNames.GroupVertices, TableNames.GroupVertices, WorksheetNames.GroupEdgeMetrics, TableNames.GroupEdgeMetrics ); }