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 (!ExcelUtil.TryGetTableColumnData(oTable, CommonTableColumnNames.ID, out oIDColumnData)) { return(false); } return(true); }
//************************************************************************* // Method: WriteGraphMetricColumnWithIDToWorkbook() // /// <summary> /// Writes a GraphMetricColumnWithID object to the workbook. /// </summary> /// /// <param name="oGraphMetricColumnWithID"> /// The GraphMetricColumnWithID object to write to the workbook. /// </param> /// /// <param name="oTable"> /// The table containing the column. /// </param> //************************************************************************* protected void WriteGraphMetricColumnWithIDToWorkbook( GraphMetricColumnWithID oGraphMetricColumnWithID, ListObject oTable ) { Debug.Assert(oGraphMetricColumnWithID != null); Debug.Assert(oTable != null); AssertValid(); // Get the required column information. Range oVisibleColumnData, oIDColumnData; if ( !TryGetRequiredColumnWithIDInformation(oGraphMetricColumnWithID, oTable, out oVisibleColumnData, out oIDColumnData) ) { return; } // Store the column's GraphMetricValueWithID objects in a dictionary. // The key is the GraphMetricValueWithID.RowID and the value is the // GraphMetricValueWithID. Dictionary<Int32, GraphMetricValueWithID> oIDDictionary = new Dictionary<Int32, GraphMetricValueWithID>(); foreach (GraphMetricValueWithID oGraphMetricValueWithID in oGraphMetricColumnWithID.GraphMetricValuesWithID) { oIDDictionary.Add(oGraphMetricValueWithID.RowID, oGraphMetricValueWithID); } Debug.Assert(oTable.Parent is Worksheet); Worksheet oWorksheet = (Worksheet)oTable.Parent; Int32 iIDColumnNumberOneBased = oIDColumnData.Column; // Loop through the areas, and split each area into subranges if the // area contains too many rows. foreach ( Range oColumnSubrange in ExcelRangeSplitter.SplitRange(oVisibleColumnData) ) { Int32 iRows = oColumnSubrange.Rows.Count; Range oIDColumnSubrange = ExcelRangeSplitter.GetParallelSubrange( oColumnSubrange, iIDColumnNumberOneBased); Debug.Assert(oIDColumnSubrange.Rows.Count == iRows); Object [,] aoColumnValues = ExcelUtil.GetSingleColumn2DArray(iRows); Object [,] aoIDColumnValues = ExcelUtil.GetRangeValues(oIDColumnSubrange); // Loop through the rows. for (Int32 iRowOneBased = 1; iRowOneBased <= iRows; iRowOneBased++) { String sID; Int32 iID; // Get the ID stored in the row. if ( !ExcelUtil.TryGetNonEmptyStringFromCell( aoIDColumnValues, iRowOneBased, 1, out sID) || !Int32.TryParse(sID, out iID) ) { continue; } // Is the ID one of the IDs specified within the // GraphMetricColumn object? GraphMetricValueWithID oGraphMetricValueWithID; if ( !oIDDictionary.TryGetValue(iID, out oGraphMetricValueWithID) ) { // No. continue; } // Set the column cell in this row to the specified value. aoColumnValues[iRowOneBased, 1] = oGraphMetricValueWithID.Value; } oColumnSubrange.set_Value(Missing.Value, aoColumnValues); } }
WriteGraphMetricColumnWithIDToWorkbook ( GraphMetricColumnWithID oGraphMetricColumnWithID, ListObject oTable ) { Debug.Assert(oGraphMetricColumnWithID != null); Debug.Assert(oTable != null); AssertValid(); // Get the required column information. Range oVisibleColumnData, oIDColumnData; if (!TryGetRequiredColumnWithIDInformation(oGraphMetricColumnWithID, oTable, out oVisibleColumnData, out oIDColumnData)) { return; } // Store the column's GraphMetricValueWithID objects in a dictionary. // The key is the GraphMetricValueWithID.RowID and the value is the // GraphMetricValueWithID. Dictionary <Int32, GraphMetricValueWithID> oIDDictionary = new Dictionary <Int32, GraphMetricValueWithID>(); foreach (GraphMetricValueWithID oGraphMetricValueWithID in oGraphMetricColumnWithID.GraphMetricValuesWithID) { oIDDictionary.Add(oGraphMetricValueWithID.RowID, oGraphMetricValueWithID); } Debug.Assert(oTable.Parent is Worksheet); Worksheet oWorksheet = (Worksheet)oTable.Parent; Int32 iIDColumnNumberOneBased = oIDColumnData.Column; // Loop through the areas, and split each area into subranges if the // area contains too many rows. foreach (Range oColumnSubrange in ExcelRangeSplitter.SplitRange(oVisibleColumnData)) { Int32 iRows = oColumnSubrange.Rows.Count; Range oIDColumnSubrange = ExcelRangeSplitter.GetParallelSubrange( oColumnSubrange, iIDColumnNumberOneBased); Debug.Assert(oIDColumnSubrange.Rows.Count == iRows); Object [,] aoColumnValues = ExcelUtil.GetSingleColumn2DArray(iRows); Object [,] aoIDColumnValues = ExcelUtil.GetRangeValues(oIDColumnSubrange); // Loop through the rows. for (Int32 iRowOneBased = 1; iRowOneBased <= iRows; iRowOneBased++) { String sID; Int32 iID; // Get the ID stored in the row. if ( !ExcelUtil.TryGetNonEmptyStringFromCell( aoIDColumnValues, iRowOneBased, 1, out sID) || !Int32.TryParse(sID, out iID) ) { continue; } // Is the ID one of the IDs specified within the // GraphMetricColumn object? GraphMetricValueWithID oGraphMetricValueWithID; if (!oIDDictionary.TryGetValue(iID, out oGraphMetricValueWithID)) { // No. continue; } // Set the column cell in this row to the specified value. aoColumnValues[iRowOneBased, 1] = oGraphMetricValueWithID.Value; } oColumnSubrange.set_Value(Missing.Value, aoColumnValues); } }
//************************************************************************* // Method: TryGetRequiredColumnWithIDInformation() // /// <summary> /// Gets the column information required to write a GraphMetricColumnWithID /// object to the workbook. /// </summary> /// /// <param name="oGraphMetricColumnWithID"> /// The GraphMetricColumnWithID object to write to the workbook. /// </param> /// /// <param name="oTable"> /// The table containing the column. /// </param> /// /// <param name="oVisibleColumnData"> /// Where the visible range of the specified column gets stored if true is /// returned. /// </param> /// /// <param name="oIDColumnData"> /// Where the ID column gets stored if true is returned. The column may /// contain hidden rows. /// </param> /// /// <returns> /// true if the column information was obtained. /// </returns> //************************************************************************* protected Boolean 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 ( !ExcelUtil.TryGetTableColumnData(oTable, CommonTableColumnNames.ID, out oIDColumnData) ) { return (false); } return (true); }