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); } } }
//************************************************************************* // Method: PopulateEdgeTableWithParticipantPairs() // /// <summary> /// Populates the edge table with an array of participant pairs. /// </summary> /// /// <param name="edgeTable"> /// The edge table to populate. /// </param> /// /// <param name="participantPairs"> /// Zero or more <see cref="ParticipantPair" /> objects. /// </param> /// /// <param name="edgeTableRowOffset"> /// Offset of the first row in the edge table to write to, measured from /// the first data body row. /// </param> /// /// <remarks> /// This method populates the edge table with pairs of participants in a /// social network. The Vertex 1 column is filled with the first /// participant in each pair and the Vertex 2 column is filled with the /// second participant in each pair. /// /// <para> /// If either column is missing, this method skips it. /// </para> /// /// </remarks> //************************************************************************* public static void 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 ( ExcelUtil.TryGetTableColumnData(edgeTable, sColumnName, out oVertexColumnData) ) { ExcelUtil.OffsetRange(ref oVertexColumnData, edgeTableRowOffset, 0); ExcelUtil.SetRangeValues(oVertexColumnData, sColumnName == EdgeTableColumnNames.Vertex1Name ? aoVertex1Names : aoVertex2Names); } } }