Smrf.NodeXL.ExcelTemplate.WorkbookAutoFiller.PrependGroupLabelsWithGroupNames C# (CSharp) Method

PrependGroupLabelsWithGroupNames() private static method

private static PrependGroupLabelsWithGroupNames ( ListObject oGroupTable ) : void
oGroupTable ListObject
return void
    PrependGroupLabelsWithGroupNames
    (
        ListObject oGroupTable
    )
    {
        Debug.Assert(oGroupTable != null);

        // Use ExcelTableReader to accomplish the task with minimal code.
        //
        // Note that ExcelTableReader is optimized for reading, and that its
        // use for writing incurs the overhead of a COM call for each written
        // cell.  There typically aren't many groups, though, so this is
        // probably tolerable.
        //
        // If this turns out to be too slow, something similar to the code in
        // TableColumnMapper.MapViaCopy() will need to be implemented.

        ExcelTableReader oExcelTableReader = new ExcelTableReader(oGroupTable);

        if (
            oExcelTableReader.ColumnNames.Contains(GroupTableColumnNames.Name)
            &&
            oExcelTableReader.ColumnNames.Contains(GroupTableColumnNames.Label)
            )
        {
            foreach (ExcelTableReader.ExcelTableRow oRow in
                oExcelTableReader.GetRows() )
            {
                String sName;

                if ( oRow.TryGetNonEmptyStringFromCell(
                    GroupTableColumnNames.Name, out sName) )
                {
                    String sLabel;

                    if ( oRow.TryGetNonEmptyStringFromCell(
                        GroupTableColumnNames.Label, out sLabel) )
                    {
                        sName += ": " + sLabel;
                    }

                    oRow.GetRangeForCell(GroupTableColumnNames.Label)
                        .set_Value(Missing.Value, sName);
                }
            }
        }
    }