using System.Data;
using System.Data.OleDb;
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\txl.xls;Extended Properties=Excel 8.0;";
OleDbConnection con = new OleDbConnection(connectionString);
con.Open();
OleDbCommand command = new OleDbCommand("SELECT * FROM [Sheet1$]", con);
//方法一(读取方式显示)
//OleDbDataReader reader = command.ExecuteReader();
//string mgf = string.Empty;
//while (reader.Read())
//{
// int count = reader.FieldCount;
// string rowstring = "";
// for (int i = 0; i < count; i++)
// {
// string item = reader[i].ToString();
// mgf += item+"<br />";
// }
//}
//Response.Write(mgf);
//方法二(GridView表格方式显示)
System.Data.OleDb.OleDbDataAdapter oleda = new System.Data.OleDb.OleDbDataAdapter(command);
System.Data.DataSet ds = new DataSet();
oleda.Fill(ds, "[Sheet1$]");
GridView1.DataSource = ds;
GridView1.DataBind();
- 本文标题: ASP.NET 读取Excel
- 文章分类:【.NET/Web】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.