SetLocations <TLocationInfo> ( IEnumerable <TLocationInfo> oLocationInfo, System.Drawing.Rectangle oGraphRectangle, TryGetRowIDAndLocation <TLocationInfo> oTryGetRowIDAndLocation, Dictionary <Int32, Int32> oRowIDDictionary, Range oXColumnData, Range oYColumnData, Object [,] aoLockedColumnValues ) { Debug.Assert(oLocationInfo != null); Debug.Assert(oTryGetRowIDAndLocation != null); Debug.Assert(oRowIDDictionary != null); Debug.Assert(oXColumnData != null); Debug.Assert(oYColumnData != null); AssertValid(); Int32 iRowNumberOneBased; Object [,] aoXValues = ExcelUtil.GetRangeValues(oXColumnData); Object [,] aoYValues = ExcelUtil.GetRangeValues(oYColumnData); // This is the row number of the table's first data row. Int32 iDataBodyRangeRowOneBased = oXColumnData.Row; // Create an object that converts a location between coordinates used // in the NodeXL graph and coordinates used in the worksheet. VertexLocationConverter oVertexLocationConverter = new VertexLocationConverter(oGraphRectangle); foreach (TLocationInfo oOneLocationInfo in oLocationInfo) { Int32 iRowID; PointF oLocationToSet; if ( !oTryGetRowIDAndLocation(oOneLocationInfo, out iRowID, out oLocationToSet) || !oRowIDDictionary.TryGetValue(iRowID, out iRowNumberOneBased) ) { continue; } Int32 iRowToWriteOneBased = iRowNumberOneBased - iDataBodyRangeRowOneBased + 1; if ( aoLockedColumnValues != null && VertexIsLocked(aoLockedColumnValues, iRowToWriteOneBased) ) { continue; } // Convert the location to workbook coordinates before writing it // to the X and Y column cells. Single fWorkbookX, fWorkbookY; oVertexLocationConverter.GraphToWorkbook(oLocationToSet, out fWorkbookX, out fWorkbookY); aoXValues[iRowToWriteOneBased, 1] = fWorkbookX; aoYValues[iRowToWriteOneBased, 1] = fWorkbookY; } // Write the X and Y columns. oXColumnData.set_Value(Missing.Value, aoXValues); oYColumnData.set_Value(Missing.Value, aoYValues); }
SetLocations <TLocationInfo> ( ICollection <TLocationInfo> locationInfo, System.Drawing.Rectangle graphRectangle, String xColumnName, String yColumnName, String lockedColumnName, TryGetRowIDAndLocation <TLocationInfo> tryGetRowIDAndLocation ) { Debug.Assert(locationInfo != null); Debug.Assert(!String.IsNullOrEmpty(xColumnName)); Debug.Assert(!String.IsNullOrEmpty(yColumnName)); Debug.Assert(tryGetRowIDAndLocation != null); AssertValid(); if (locationInfo.Count == 0) { return; } // Gather some required information. ListObject oTable = m_oTable.InnerObject; Range oXColumnData, oYColumnData, oLockedColumnData; Object [,] aoLockedColumnValues = null; // The key is a row ID and the value is the row's one-based row number // relative to the worksheet. Dictionary <Int32, Int32> oRowIDDictionary; if ( TryGetAllRowIDs(out oRowIDDictionary) && ExcelTableUtil.TryGetTableColumnData(oTable, xColumnName, out oXColumnData) && ExcelTableUtil.TryGetTableColumnData(oTable, yColumnName, out oYColumnData) && ( lockedColumnName == null || ExcelTableUtil.TryGetTableColumnDataAndValues(oTable, lockedColumnName, out oLockedColumnData, out aoLockedColumnValues) ) ) { // Activate this worksheet, because writing to an inactive // worksheet causes problems with the selection in Excel. ExcelActiveWorksheetRestorer oExcelActiveWorksheetRestorer = GetExcelActiveWorksheetRestorer(); ExcelActiveWorksheetState oExcelActiveWorksheetState = oExcelActiveWorksheetRestorer.ActivateWorksheet( m_oWorksheet.InnerObject); try { SetLocations <TLocationInfo>(locationInfo, graphRectangle, tryGetRowIDAndLocation, oRowIDDictionary, oXColumnData, oYColumnData, aoLockedColumnValues); } finally { oExcelActiveWorksheetRestorer.Restore( oExcelActiveWorksheetState); } } }