Smrf.NodeXL.ExcelTemplate.GraphMetricWriter.TryGetRequiredColumnInformation C# (CSharp) Method

TryGetRequiredColumnInformation() protected method

protected TryGetRequiredColumnInformation ( GraphMetricColumn oGraphMetricColumn, ListObject oTable, Range &oVisibleColumnData ) : System.Boolean
oGraphMetricColumn GraphMetricColumn
oTable ListObject
oVisibleColumnData Range
return System.Boolean
    TryGetRequiredColumnInformation
    (
        GraphMetricColumn oGraphMetricColumn,
        ListObject oTable,
        out Range oVisibleColumnData
    )
    {
        Debug.Assert(oGraphMetricColumn != null);
        Debug.Assert(oTable != null);
        AssertValid();

        oVisibleColumnData = null;

        // Add the specified column if it's not already present.

        String sColumnName = oGraphMetricColumn.ColumnName;
        String sColumnStyle = oGraphMetricColumn.Style;

        Microsoft.Office.Interop.Excel.ListColumn oColumn;

        if (
            !ExcelTableUtil.TryGetTableColumn(oTable, sColumnName, out oColumn)
            &&
            !ExcelTableUtil.TryAddTableColumn(oTable, sColumnName,
                oGraphMetricColumn.ColumnWidthChars, sColumnStyle, out oColumn)
            )
        {
            // Give up.

            return (false);
        }

        Range oColumnData;

        if (!ExcelTableUtil.TryGetTableColumnData(oTable, sColumnName,
            out oColumnData) )
        {
            return (false);
        }

        ExcelUtil.SetRangeStyle(oColumnData, sColumnStyle);

        String sNumberFormat = oGraphMetricColumn.NumberFormat;

        if (sNumberFormat != null)
        {
            oColumnData.NumberFormat = sNumberFormat;
        }

        // Wrapping text makes Range.set_Value() very slow, so turn it off.

        oColumn.Range.WrapText = false;

        // But wrap the text in the column's header.

        ExcelTableUtil.WrapTableColumnHeader(oColumn);

        // Get the visible range.

        if ( !ExcelUtil.TryGetVisibleRange(oColumnData,
            out oVisibleColumnData) )
        {
            return (false);
        }

        return (true);
    }