头文件:

C#将Excel中的数据读入DataGridusing System;
C#将Excel中的数据读入DataGrid
using System.Drawing;
C#将Excel中的数据读入DataGrid
using System.Collections;
C#将Excel中的数据读入DataGrid
using System.ComponentModel;
C#将Excel中的数据读入DataGrid
using System.Windows.Forms;
C#将Excel中的数据读入DataGrid
using System.Data;
C#将Excel中的数据读入DataGrid
using System.Data.OleDb;

代码:
C#将Excel中的数据读入DataGridstring strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
C#将Excel中的数据读入DataGrid                
@"Data Source=xls路径;"+
C#将Excel中的数据读入DataGrid                
@"Extended Properties=Excel 8.0;";
C#将Excel中的数据读入DataGrid            OleDbConnection conn 
= new OleDbConnection(strConn);
C#将Excel中的数据读入DataGrid            OleDbDataAdapter myCommand 
= new OleDbDataAdapter("SELECT * FROM [Excel的Sheet名$]", strConn);
C#将Excel中的数据读入DataGrid            DataSet myDataSet 
= new DataSet();
C#将Excel中的数据读入DataGrid            myCommand.Fill(myDataSet);
C#将Excel中的数据读入DataGrid            
this.dataGrid1.DataSource=myDataSet;
C#将Excel中的数据读入DataGrid            
this.dataGrid1.DataMember=myDataSet.Tables[0].TableName;

相关文章: