qianbao

文采有限,写不出系统的文章....所以只能记录一些小小的知识点
没有真正的捷径能绕过黑暗直达黎明..

2008年5月31日 #

Excel to gridview

protected void Button1_Click(object sender, EventArgs e)
        {
            
if (this.FileUpload1.HasFile)
            {
                
// FileInfo file = new FileInfo(this.FileUpload1.FileName);
                this.FileUpload1.PostedFile.SaveAs(Server.MapPath(this.FileUpload1.FileName));
                
//string con = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath(this.FileUpload1.FileName) + ";Extended Properties=Excel 8.0; ";//下面连接字符串03和07都支持
                string con = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath(this.FileUpload1.FileName) + ";Extended Properties=\"Excel 12.0;HDR=YES\";";
                OleDbConnection objCon 
= new OleDbConnection(con);
                
string strSel = "select * from [Sheet1$]";
                OleDbDataAdapter objAdapter 
= new OleDbDataAdapter(strSel, objCon);
                DataSet ds 
= new DataSet();
                objCon.Open();
                objAdapter.Fill(ds);
                objCon.Close();
                
this.GridView1.DataSource = ds;
                
this.GridView1.DataBind();
            }
        }

posted @ 2008-05-31 12:18 qianbao 阅读(15) | 评论 (0)编辑

上传文件

 
 if (this.FileUpload1.HasFile)
            {
               
// FileInfo file = new FileInfo(this.FileUpload1.FileName);
                this.FileUpload1.PostedFile.SaveAs(Server.MapPath(this.FileUpload1.FileName));
            }

posted @ 2008-05-31 11:55 qianbao 阅读(11) | 评论 (0)编辑