Exemple #1
0
        SetRangeValues
        (
            Range oUpperLeftCornerMarker,
            Object [,] aoValues,
            Boolean bConvertUrlsToHyperlinks
        )
        {
            Debug.Assert(oUpperLeftCornerMarker != null);
            Debug.Assert(aoValues != null);

            Range oActualRange = ExcelUtil.SetRangeValues(oUpperLeftCornerMarker,
                                                          aoValues, true);

            if (bConvertUrlsToHyperlinks)
            {
                ExcelUtil.ConvertUrlsToHyperlinks(oActualRange);
            }

            // If a cell value contains line breaks, Excel increases the row height
            // to make all the lines in the cell visible.  It does this even if the
            // column's formatting is set to not wrap text before the values are
            // written.  Setting WrapText to false after the values are written
            // sets the row back to the default height.
            //
            // Unfortunately, this introduces another bug: the cell borders
            // sometime disappear when wrap text is turned off here.  For now,
            // that's a less annoying bug than the row height problem.

            oActualRange.WrapText = false;
        }
Exemple #2
0
        WriteGraphMetricColumnOrderedToWorkbook
        (
            GraphMetricColumnOrdered oGraphMetricColumnOrdered,
            ListObject oTable
        )
        {
            Debug.Assert(oGraphMetricColumnOrdered != null);
            Debug.Assert(oTable != null);
            AssertValid();

            GraphMetricValueOrdered [] aoGraphMetricValuesOrdered =
                oGraphMetricColumnOrdered.GraphMetricValuesOrdered;

            Int32 iRows = aoGraphMetricValuesOrdered.Length;

            // Make sure the table has enough rows.

            ResizeTable(oTable, iRows);

            Range oVisibleColumnData;

            // Get the specified column.

            if (!TryGetRequiredColumnInformation(oGraphMetricColumnOrdered,
                                                 oTable, out oVisibleColumnData))
            {
                return;
            }

            // Copy the graph metric values to an array.

            Object [,] aoValues = ExcelUtil.GetSingleColumn2DArray(iRows);
            Boolean bStyleSpecified = false;

            for (Int32 i = 0; i < iRows; i++)
            {
                GraphMetricValueOrdered oGraphMetricValueOrdered =
                    aoGraphMetricValuesOrdered[i];

                aoValues[i + 1, 1] = oGraphMetricValueOrdered.Value;

                if (oGraphMetricValueOrdered.Style != null)
                {
                    // A style was specified for this row.  It will need to be
                    // applied later.  (It should be possible to apply the style
                    // here, but that does not work reliably when values are
                    // written to the cells afterwards, as they are after this
                    // loop.)

                    bStyleSpecified = true;
                }
            }

            // Write the array to the column.

            Range oWrittenRange = ExcelUtil.SetRangeValues(
                oVisibleColumnData, aoValues);

            if (oGraphMetricColumnOrdered.ConvertUrlsToHyperlinks)
            {
                ExcelUtil.ConvertUrlsToHyperlinks(oWrittenRange);
            }

            if (bStyleSpecified)
            {
                for (Int32 i = 0; i < iRows; i++)
                {
                    String sStyle = aoGraphMetricValuesOrdered[i].Style;

                    if (sStyle != null)
                    {
                        // This row has a style.  Apply it.

                        ExcelUtil.SetRangeStyle(
                            (Range)oVisibleColumnData.Cells[i + 1, 1], sStyle);
                    }
                }
            }
        }
Exemple #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);
                }
            }
        }