Stores an entire column of graph metric values, where the values are mapped to worksheet rows by row IDs.
The graph metric value returned by GraphMetricValuesWithID should be written to the worksheet rows identified by the property. (Row IDs get written to the worksheet when the worksheet is read by WorkbookReader.)
Inheritance: GraphMetricColumn
Esempio n. 1
0
        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);
        }
    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);
    }
Esempio n. 3
0
        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);

                if (oGraphMetricColumnWithID.ConvertUrlsToHyperlinks)
                {
                    ExcelUtil.ConvertUrlsToHyperlinks(oColumnSubrange);
                }
            }
        }
    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);

            if (oGraphMetricColumnWithID.ConvertUrlsToHyperlinks)
            {
                ExcelUtil.ConvertUrlsToHyperlinks(oColumnSubrange);
            }
        }
    }