|
发表于 2020-12-10 18:30:01
|
显示全部楼层
System.Data.OleDb.OleDbConnection cn = new System.Data.OleDb.OleDbConnection();
cn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Book1.xls;Extended Properties=Excel 8.0;";
cn.Open();
string sql = "select * from [Sheet1$A2:F10]";
System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand(sql, cn);
System.Data.OleDb.OleDbDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
MessageBox.Show(dr[0].ToString());
}
cn.Close();
用上面的语句先连接再添加 |
|