Smrf.NodeXL.ExcelTemplate.DuplicateEdgeMerger.DeleteMarkedRows C# (CSharp) Method

DeleteMarkedRows() protected method

protected DeleteMarkedRows ( ListObject oEdgeTable, Range oDeleteIfEmptyData, Object aoDeleteIfEmptyValues ) : void
oEdgeTable ListObject
oDeleteIfEmptyData Range
aoDeleteIfEmptyValues Object
return void
    DeleteMarkedRows
    (
        ListObject oEdgeTable,
        Range oDeleteIfEmptyData,
        Object [,] aoDeleteIfEmptyValues
    )
    {
        Debug.Assert(oEdgeTable != null);
        Debug.Assert(oDeleteIfEmptyData != null);
        Debug.Assert(aoDeleteIfEmptyValues != null);
        AssertValid();

        Range oMarkedRows = null;

        if (oDeleteIfEmptyData.Rows.Count != 1)
        {
            try
            {
                oMarkedRows = oDeleteIfEmptyData.SpecialCells(
                    XlCellType.xlCellTypeBlanks, Missing.Value);
            }
            catch (COMException)
            {
                // There are no such rows.

                oMarkedRows = null;
            }
        }
        else
        {
            // Range.SpecialCells() can't be used in the one-cell case, for
            // which it behaves in a bizarre manner.  See this posting:
            //
            // http://ewbi.blogs.com/develops/2006/03/determine_if_a_.html
            //
            // ...of which this is an excerpt:
            //
            // "SpecialCells ignores any source Range consisting of only one
            // cell. When executing SpecialCells on a Range having only one
            // cell, it will instead consider all of the cells falling within
            // the boundary marked by the bottom right cell of the source Range
            // sheet's UsedRange."
            //
            // Instead, just check the single row.

            if (aoDeleteIfEmptyValues[1, 1] == null)
            {
                oMarkedRows = oDeleteIfEmptyData.EntireRow;
            }
        }

        if (oMarkedRows != null)
        {
            // Delete the marked rows, which are now contiguous.

            Debug.Assert(oMarkedRows.Areas.Count == 1);

            oMarkedRows.EntireRow.Delete(XlDeleteShiftDirection.xlShiftUp);
        }
    }