简体   繁体   中英

How to Import All Excel Sheet in Gridview in asp.net?

我已经在excel中创建了一个出勤表,我想在gridview中显示所有表格,例如班级出勤报告,学生出勤报告等,有人可以帮我吗?

You should import your sheets into a DataSet object, and then bind it to a GridView.
Take a look at those links:
Excel Sheet to DataSet: link_1
Bind DataSet to Gridview: link_2

   List<string> excelName = new List<string>();   
   DataSet ds = new DataSet();  
   foreach(var name in excelName )
    {
        using (SqlConnection con = new SqlConnection(connectionString))
        {        
            DataTable dt = new DataTable();
            string query ="select * from '"+name+"'";
            con.Open();
            SqlDataAdapter da = new OleDbDataAdapter(query, con);
            da.Fill(dt);
            con.Close();    
            ds.add(dt);            
        }
    }

    gridview.DataSource = ds;
    gridview.DataBind();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM