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);
}
}
}
}