基本信息
源码名称:C# Addin Vsto Excel小插件 实例源码下载
源码大小:2.23M
文件格式:.rar
开发语言:C#
更新时间:2017-06-22
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 5 元 
   源码介绍
可以根据表头筛选excel数据,并且把筛选好的数据保存到时另一个表中

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using Microsoft.Office.Tools.Excel;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
using System.IO;
using Microsoft.Office.Interop.Excel;

namespace ExcelAddIn4
{
    public partial class Search_From : UserControl
    {
        public Search_From()
        {
            InitializeComponent();
        }

        private void btn_search_Click(object sender, EventArgs e)
        {
            string SearchStr = txt_Condition.Text;
            GetValue(SearchStr);
        }


        private void FlashDate()
        { //cbb_Type
            Excel.Worksheet worksheet = (Excel.Worksheet)Globals.ThisAddIn.Application.ActiveSheet;
            Excel.Range Item = (Excel.Range)worksheet.UsedRange.Rows[1];
            List<string> list = new List<string>();
            for (int i = 0; i < Item.Cells.Count; i  )
            {
                Excel.Range rhh = Item.Cells[i   1];
                list.Add(rhh.Value);
            }
            cbb_Type.DataSource = list;
        }
        //用于筛选的方法
        private void GetValue(string Condition)
        {
            if (Condition == null)
            {
                MessageBox.Show("筛选条件为空!");
                return;
            }
            try
            {
                int CountCrete = 2;
                int subjectIndex = cbb_Type.SelectedIndex;
                Excel.Worksheet worksheet = (Excel.Worksheet)Globals.ThisAddIn.Application.ActiveSheet;
                object missing = Type.Missing;
                int count = 1;
                Excel.Worksheet CretWorkSheet = (Excel.Worksheet)Globals.ThisAddIn.Application.ActiveWorkbook.Worksheets.Add(missing, Globals.ThisAddIn.Application.ActiveWorkbook.Worksheets[/*"Sheet1"*/Globals.ThisAddIn.Application.ActiveWorkbook.Worksheets.Count], count, missing);
                if (worksheet.UsedRange.Rows.Count > 1)
                {
                    Excel.Range TitleRange = (Excel.Range)worksheet.Rows[1];
                    Excel.Range CTitleRange = CretWorkSheet.Rows[1];
                    CTitleRange.Value = TitleRange.Value;
                }
                for (int row = 1; row < worksheet.UsedRange.Rows.Count   1; row  )
                {
                    Excel.Range rng = (Excel.Range)worksheet.Cells[row, 1];
                    Excel.Range rng1 = (Excel.Range)worksheet.Cells[row, 1];
                    Excel.Range rng5 = (Excel.Range)worksheet.Rows[row];
                    Excel.Range rngS = (Excel.Range)worksheet.Cells[row, subjectIndex   1];
                    string CompareCondition = rngS.Value;
                    if (CompareCondition == null)
                        continue;
                    if (CompareCondition.Contains(Condition))
                    {
                        Excel.Range rngd1 = CretWorkSheet.Rows[CountCrete];
                        rngd1.Value = rng5.Value;
                        CountCrete  ;
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("出错了!");
            }
        }

        private void btn_Loading_Click(object sender, EventArgs e)
        {
            FlashDate();
        }
    }
}