请问C#如何导入Excel,需要什么文件,如何在VS中加载,还有操作代码。
        网上只有操作代码,不够详细。

解决方案 »

  1.   

    DataSet ds=new DataSet(); 
                OleDbConnection oleDbConnection = null; 
                try 
                { 
                    oleDbConnection =new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties=\"Excel 8.0;IMEX=1;\""); 
                    OleDbCommand selectCommand = new OleDbCommand(); 
                    selectCommand.Connection = oleDbConnection; 
                    selectCommand.CommandText = "select * from [" + sheetName +"]"; 
                  selectCommand.CommandType = CommandType.Text; 
                    OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommand); 
                    ds= new DataSet(); 
                  adapter.Fill(ds); 
                } 
                catch (Exception exception) 
                { 
                    oleDbConnection.Close(); 
                } 
              finally 
                {                
                    oleDbConnection.Close(); 
                } 
    http://topic.csdn.net/u/20091011/09/bc1d10cc-dc8f-40c0-b6c8-75c31da020ff.html
      

  2.   

    还有EXCEL版本问题要注意下。。