当前位置:软件学习 > Excel >>

字符串检索-递归遍历文件夹-excel读取成dataset-结果导入到excel

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.IO;
using System.Data.OleDb;

namespace ProCheck
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            progressBar1.Visible = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try {
                label5.Text = "Checking!";
                string filename = excelpath.Text;
                DataSet ds;
                string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                                "Extended Properties=Excel 8.0;" +
                                "data source=" + filename;
                OleDbConnection myConn = new OleDbConnection(strCon);
                string strCom = " SELECT * FROM [Sheet1$]";
                myConn.Open();
                OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
                ds = new DataSet();
                myCommand.Fill(ds);

                DataTable Exceldt = ds.Tables[0];
                string proName;

                progressBar1.Refresh();
                progressBar1.Visible = true;
                progressBar1.Minimum = 1;
                progressBar1.Maximum = Exceldt.Rows.Count;
                progressBar1.Step = 1;

                //for (int i = 0; i < 507;i++ )
                for (int i = 0; i < Exceldt.Rows.Count; i++)
                {
                    progressBar1.PerformStep();
                    proName = Convert.ToString(Exceldt.Rows[i][0]);

                    string currentdir = dpath.Text;
                    if (currentdir[currentdir.Length - 1] != '\\')   //非根目录 
                        currentdir += "\\";

                    DirectoryInfo Dir = new DirectoryInfo(currentdir);

                    //if (FindFile(currentdir, proName))               
                    if (FindFile(Dir, proName))
                    {

                        Exceldt.Rows[i][1] = "1";

                    }
                    else {
                        Exceldt.Rows[i][1] = "0";
                    }
                }

                myConn.Close();
                //return ds;    
                label5.Text = "Checking Completed!";
                SaveToExcel(Exceldt);
                label5.Text = "Over!";
                progressBar1.Visible = false;           
            }
            catch(Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }

        public Boolean FindFile(DirectoryInfo dd, string proname)
        {

            FileInfo[]

补充:软件开发 , C# ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,