怎样利用EXCEL表倒入dataset的方法,解决读ExceL问题.

解决方案 »

  1.   

     public static DataSet ExcelToDS(string Path)
            {
                DataSet ds = new DataSet();
                try
                {
                    string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
                    OleDbConnection conn = new OleDbConnection(strConn);
                    conn.Open();
                    string strExcel = "";
                    OleDbDataAdapter myCommand = null;
                    strExcel = "select * from [sheet1$] ";
                    myCommand = new OleDbDataAdapter(strExcel, strConn);                myCommand.Fill(ds, "sheet1");
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
                return ds;
            }