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) ); }
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) ); }
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); }
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); }
TryGetInformationFromEdgeTable ( Microsoft.Office.Interop.Excel.Workbook oWorkbook, ListObject oEdgeTable, String sThirdColumnName, out Boolean bGraphIsDirected, out Range oVertex1NameData, out Object [,] aoVertex1NameValues, out Range oVertex2NameData, out Object [,] aoVertex2NameValues, out Object [,] aoThirdColumnValues ) { Debug.Assert(oWorkbook != null); Debug.Assert(oEdgeTable != null); AssertValid(); oVertex1NameData = oVertex2NameData = null; aoVertex1NameValues = aoVertex2NameValues = aoThirdColumnValues = null; bGraphIsDirected = (new PerWorkbookSettings(oWorkbook).GraphDirectedness == GraphDirectedness.Directed); Range oThirdColumnData; if ( !String.IsNullOrEmpty(sThirdColumnName) && !ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable, sThirdColumnName, out oThirdColumnData, out aoThirdColumnValues) ) { // This is not an error. aoThirdColumnValues = null; } return( ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable, EdgeTableColumnNames.Vertex1Name, out oVertex1NameData, out aoVertex1NameValues) && ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable, EdgeTableColumnNames.Vertex2Name, out oVertex2NameData, out aoVertex2NameValues) ); }
GetAllSettings() { AssertValid(); if (m_oSettings == null) { m_oSettings = new Dictionary <String, Object>(); // Attempt to get the optional table and table columns that contain // the settings. ListObject oPerWorkbookSettingsTable; Range oNameColumnData, oValueColumnData; Object [,] aoNameColumnValues, aoValueColumnValues; if ( TryGetPerWorkbookSettingsTable(out oPerWorkbookSettingsTable) && ExcelTableUtil.TryGetTableColumnDataAndValues( oPerWorkbookSettingsTable, PerWorkbookSettingsTableColumnNames.Name, out oNameColumnData, out aoNameColumnValues) && ExcelTableUtil.TryGetTableColumnDataAndValues( oPerWorkbookSettingsTable, PerWorkbookSettingsTableColumnNames.Value, out oValueColumnData, out aoValueColumnValues) ) { Int32 iRows = oNameColumnData.Rows.Count; for (Int32 iRowOneBased = 1; iRowOneBased <= iRows; iRowOneBased++) { String sName; if (ExcelUtil.TryGetNonEmptyStringFromCell( aoNameColumnValues, iRowOneBased, 1, out sName)) { m_oSettings[sName] = aoValueColumnValues[iRowOneBased, 1]; } } } } return(m_oSettings); }
ThisWorkbook_AttributesEditedInGraph ( Object sender, AttributesEditedEventArgs e ) { Debug.Assert(e != null); AssertValid(); // The key is the row ID stored in the table's ID column and the value // is the one-based row number relative to the worksheet. Dictionary <Int32, Int32> oRowIDDictionary; if ( e.EditedEdgeAttributes == null || !m_oSheets1And2Helper.TableExists || !m_oSheets1And2Helper.TryGetAllRowIDs(out oRowIDDictionary) ) { return; } Microsoft.Office.Interop.Excel.ListObject oEdgeTable = Edges.InnerObject; Globals.ThisWorkbook.ShowWaitCursor = true; // Get the columns that might need to be updated. These columns are // not required. Microsoft.Office.Interop.Excel.Range oColorColumnData, oWidthColumnData, oStyleColumnData, oAlphaColumnData, oVisibilityColumnData, oLabelColumnData, oLabelTextColorColumnData, oLabelFontSizeColumnData; Object [,] aoColorValues = null; Object [,] aoWidthValues = null; Object [,] aoStyleValues = null; Object [,] aoAlphaValues = null; Object [,] aoVisibilityValues = null; Object [,] aoLabelValues = null; Object [,] aoLabelTextColorValues = null; Object [,] aoLabelFontSizeValues = null; ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable, EdgeTableColumnNames.Color, out oColorColumnData, out aoColorValues); ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable, EdgeTableColumnNames.Width, out oWidthColumnData, out aoWidthValues); ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable, EdgeTableColumnNames.Style, out oStyleColumnData, out aoStyleValues); ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable, CommonTableColumnNames.Alpha, out oAlphaColumnData, out aoAlphaValues); ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable, CommonTableColumnNames.Visibility, out oVisibilityColumnData, out aoVisibilityValues); ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable, EdgeTableColumnNames.Label, out oLabelColumnData, out aoLabelValues); ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable, EdgeTableColumnNames.LabelTextColor, out oLabelTextColorColumnData, out aoLabelTextColorValues); ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable, EdgeTableColumnNames.LabelFontSize, out oLabelFontSizeColumnData, out aoLabelFontSizeValues); ColorConverter2 oColorConverter2 = new ColorConverter2(); EdgeStyleConverter oEdgeStyleConverter = new EdgeStyleConverter(); EdgeVisibilityConverter oEdgeVisibilityConverter = new EdgeVisibilityConverter(); // Loop through the IDs of the edges whose attributes were edited // in the graph. EditedEdgeAttributes oEditedEdgeAttributes = e.EditedEdgeAttributes; foreach (Int32 iID in e.EdgeIDs) { // Look for the row that contains the ID. Int32 iRowOneBased; if (!oRowIDDictionary.TryGetValue(iID, out iRowOneBased)) { continue; } iRowOneBased -= oEdgeTable.Range.Row; if (oEditedEdgeAttributes.Color.HasValue && aoColorValues != null) { aoColorValues[iRowOneBased, 1] = oColorConverter2.GraphToWorkbook( oEditedEdgeAttributes.Color.Value); } if (oEditedEdgeAttributes.Width.HasValue && aoWidthValues != null) { aoWidthValues[iRowOneBased, 1] = oEditedEdgeAttributes.Width.Value.ToString(); } if (oEditedEdgeAttributes.Style.HasValue && aoStyleValues != null) { aoStyleValues[iRowOneBased, 1] = oEdgeStyleConverter.GraphToWorkbook( oEditedEdgeAttributes.Style.Value); } if (oEditedEdgeAttributes.Alpha.HasValue && aoAlphaValues != null) { aoAlphaValues[iRowOneBased, 1] = oEditedEdgeAttributes.Alpha.Value.ToString(); } if (oEditedEdgeAttributes.Visibility.HasValue && aoVisibilityValues != null) { aoVisibilityValues[iRowOneBased, 1] = oEdgeVisibilityConverter.GraphToWorkbook( oEditedEdgeAttributes.Visibility.Value); } if (!String.IsNullOrEmpty(oEditedEdgeAttributes.Label)) { aoLabelValues[iRowOneBased, 1] = oEditedEdgeAttributes.Label; } if (oEditedEdgeAttributes.LabelTextColor.HasValue && aoLabelTextColorValues != null) { aoLabelTextColorValues[iRowOneBased, 1] = oColorConverter2.GraphToWorkbook( oEditedEdgeAttributes.LabelTextColor.Value); } if (oEditedEdgeAttributes.LabelFontSize.HasValue && aoLabelFontSizeValues != null) { aoLabelFontSizeValues[iRowOneBased, 1] = oEditedEdgeAttributes.LabelFontSize.Value.ToString(); } } // Activate this worksheet first, because writing to an inactive // worksheet causes problems with the selection in Excel. ExcelActiveWorksheetRestorer oExcelActiveWorksheetRestorer = m_oSheets1And2Helper.GetExcelActiveWorksheetRestorer(); ExcelActiveWorksheetState oExcelActiveWorksheetState = oExcelActiveWorksheetRestorer.ActivateWorksheet(this.InnerObject); try { m_oSheets1And2Helper.SetColumnDataValues( oColorColumnData, aoColorValues, oWidthColumnData, aoWidthValues, oStyleColumnData, aoStyleValues, oAlphaColumnData, aoAlphaValues, oVisibilityColumnData, aoVisibilityValues, oLabelColumnData, aoLabelValues, oLabelTextColorColumnData, aoLabelTextColorValues, oLabelFontSizeColumnData, aoLabelFontSizeValues ); } finally { oExcelActiveWorksheetRestorer.Restore(oExcelActiveWorksheetState); } Globals.ThisWorkbook.ShowWaitCursor = false; }
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); } } }
GetSelectedColumnValues <TValue> ( String columnName, ExcelUtil.TryGetValueFromCell <TValue> tryGetValueFromCell ) { Debug.Assert(!String.IsNullOrEmpty(columnName)); Debug.Assert(tryGetValueFromCell != null); AssertValid(); // Create a HashSet for the selected values. The HashSet key is the // cell value. HashSet <TValue> oSelectedValues = new HashSet <TValue>(); if (!this.TableExists) { goto Done; } // The selected range can extend outside the table. Get the // intersection of the table with the selection. Note that // ExcelUtil.TryGetSelectedTableRange() activates the worksheet. ListObject oTable; Range oSelectedTableRange; if (!ExcelTableUtil.TryGetSelectedTableRange( (Workbook)m_oWorksheet.Parent, m_oWorksheet.Name, m_oTable.Name, out oTable, out oSelectedTableRange)) { goto Done; } Range oDataBodyRange = m_oTable.DataBodyRange; Debug.Assert(oDataBodyRange != null); // Get data for the specified column. This includes hidden rows but // excludes the header row. Range oColumnData; Object [,] aoColumnValues; if (!ExcelTableUtil.TryGetTableColumnDataAndValues( m_oTable.InnerObject, columnName, out oColumnData, out aoColumnValues)) { goto Done; } // Read the column. foreach (Range oSelectedTableRangeArea in oSelectedTableRange.Areas) { Int32 iFirstRowOneBased = oSelectedTableRangeArea.Row - oDataBodyRange.Row + 1; Int32 iLastRowOneBased = iFirstRowOneBased + oSelectedTableRangeArea.Rows.Count - 1; for (Int32 iRowOneBased = iFirstRowOneBased; iRowOneBased <= iLastRowOneBased; iRowOneBased++) { TValue tValue; if (tryGetValueFromCell(aoColumnValues, iRowOneBased, 1, out tValue)) { oSelectedValues.Add(tValue); } } } Done: return(oSelectedValues); }