C#查找Excel()重复项

        /// <summary>
        /// 查找重复项
        /// </summary>
        /// <param name="control"></param>
        public void FindRepeat(IRibbonControl control)
        {
            Excel.Application app = ExcelDnaUtil.Application as Excel.Application;
            if (!Information.TypeName(app.Selection).Equals("Range"))
                return;

            Excel.Range rngSelection = app.Selection;
            HashSet<int> colNums = new HashSet<int>();
            foreach (Excel.Range item in rngSelection.Areas)
            {
                colNums.Add(item.Column);
            }
            List<int> colNumList = new List<int>(colNums); colNumList.Sort();

            //string msg = string.Format("{0}",string.Join("/", colNumList.ToArray()));
            //MessageBox.Show(msg);

            string msg = string.Empty;
            MyAided myAided = new MyAided(app.ActiveSheet as Excel.Worksheet);
            if (1 == colNumList.Count)
            {
                msg = myAided.FindRepeat();
            }
            else
            {
                msg = myAided.FindRepeat(colNumList.ToArray());
            }


            if (!string.IsNullOrEmpty(msg))
            {
                MessageBox.Show(msg, "重复项", MessageBoxButtons.OK);
                MyCommon.WriteLog(msg, "d:\\Log", true);

            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值