当前位置: 首页>>代码示例>>C#>>正文


C# Range.SpecialCells方法代码示例

本文整理汇总了C#中Range.SpecialCells方法的典型用法代码示例。如果您正苦于以下问题:C# Range.SpecialCells方法的具体用法?C# Range.SpecialCells怎么用?C# Range.SpecialCells使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Range的用法示例。


在下文中一共展示了Range.SpecialCells方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetSpecialCells

 private static Range GetSpecialCells(Range selectedRange, XlCellType type)
 {
     try
     {
         return selectedRange.SpecialCells(type);
     }
     catch
     {
         return null;
     }
 }
开发者ID:bdwakefield,项目名称:TrelloExcel,代码行数:11,代码来源:GridToNewCardTransformer.cs

示例2: return

        TryGetVisibleRange
        (
            Range range,
            out Range visibleRange
        )
        {
            Debug.Assert(range != null);

            visibleRange = null;

            // WARNING: If the range contains hidden cells, range.SpecialCells()
            // causes the Microsoft.Office.Tools.Excel.ListObject.SelectionChange
            // event to fire.  It shouldn't, but it does.  Allow the application to
            // work around this Excel bug by checking the SpeciealCellsBeingCalled
            // property from within the application's event handler.

            m_bSpecialCellsBeingCalled = true;

            try
            {
                if (range.Rows.Count == 1 && range.Columns.Count == 1)
                {
                    // The Range.SpecialCells() call below does not work for single
                    // cells.  For example, if range is "B3", Range.SpecialCells()
                    // returns "A:Y,AB:XFD".

                    if ((Boolean)range.EntireRow.Hidden ||
                        (Boolean)range.EntireColumn.Hidden)
                    {
                        return (false);
                    }

                    visibleRange = range;
                    return (true);
                }

                visibleRange = range.SpecialCells(
                    XlCellType.xlCellTypeVisible, Missing.Value);
            }
            catch (COMException)
            {
                // This can definitely occur.

                return (false);
            }
            finally
            {
                m_bSpecialCellsBeingCalled = false;
            }

            // Can a null visibleRange occur as well?  The documentation doesn't
            // say.

            return (visibleRange != null);
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:55,代码来源:ExcelUtil.cs

示例3: DeleteDuplicateRows

        //*************************************************************************
        //  Method: DeleteDuplicateRows()
        //
        /// <summary>
        /// Deletes the duplicate rows from the edge table.
        /// </summary>
        ///
        /// <param name="oEdgeTable">
        /// Edge table.
        /// </param>
        ///
        /// <param name="oEdgeWeightColumn">
        /// Edge weight column.
        /// </param>
        ///
        /// <param name="oEdgeWeightData">
        /// Data range for the edge weight column.
        /// </param>
        ///
        /// <param name="aoEdgeWeightValues">
        /// Data values from the edge weight column.
        /// </param>
        ///
        /// <remarks>
        /// All rows for which the edge weight cell is null are deleted.
        /// </remarks>
        //*************************************************************************
        protected void DeleteDuplicateRows(
            ListObject oEdgeTable,
            ListColumn oEdgeWeightColumn,
            Range oEdgeWeightData,
            Object [,] aoEdgeWeightValues
            )
        {
            Debug.Assert(oEdgeTable != null);
            Debug.Assert(oEdgeWeightColumn != null);
            Debug.Assert(oEdgeWeightData != null);
            Debug.Assert(aoEdgeWeightValues != null);
            AssertValid();

            Range oDuplicateRows = null;

            // Find the rows with null edge weights, which are the duplicates.  To
            // avoid multiple areas, which can slow things down signficantly, sort
            // the table on the edge weight column.  That forces the duplicates
            // to be contiguous.
            //
            // But first, add a temporary column and set its values to the
            // worksheet row numbers.  This will be used later to restore the
            // original sort order.

            ListColumn oTemporaryColumn;

            if ( !ExcelUtil.TryAddTableColumnWithRowNumbers(oEdgeTable,
            "Temporary for Sort", 5F, null, out oTemporaryColumn) )
            {
            return;
            }

            Sort oSort = oEdgeTable.Sort;
            SortFields oSortFields = oSort.SortFields;
            oSortFields.Clear();

            oSortFields.Add(oEdgeWeightColumn.Range, XlSortOn.xlSortOnValues,
            XlSortOrder.xlAscending, Missing.Value,
            XlSortDataOption.xlSortNormal);

            oSort.Apply();

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

                oDuplicateRows = 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.

//.........这里部分代码省略.........
开发者ID:haisreekanth,项目名称:NetMap,代码行数:101,代码来源:DuplicateEdgeMerger.cs

示例4: AssertValid

    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);
        }
    }
开发者ID:2014-sed-team3,项目名称:term-project,代码行数:60,代码来源:DuplicateEdgeMerger.cs


注:本文中的Range.SpecialCells方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。