鸿运当头C#/Blazor/ASP.NET/WinForm/WebAPI

因为爱上你,我才懂得珍惜,每一天日记,都写满了甜蜜
因为想念你,我每天都可以,对着镜子说我多爱你,有多想见到你。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
protected void Button1_Click(object sender, EventArgs e)
    {
        string name = FileUpload1.FileName;
        string size = FileUpload1.PostedFile.ContentLength.ToString();
        string type = FileUpload1.PostedFile.ContentType;
        string type2 = name.Substring(name.LastIndexOf(".") + 1);
        string fpath = Server.MapPath("upfile") + "\\" + name;
        if (type2 == "xls")
        {
            FileUpload1.SaveAs(fpath);
            Response.Write("文件类型:" + type + "<br>文件名:" + name + "<br>文件类型2:" + type2 + "<br>");
            Response.Write("文件路径:" + fpath);
            string strConn = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + fpath + ";Extended Properties=Excel 8.0";
            OleDbConnection conn = new OleDbConnection(strConn);
            OleDbDataAdapter adp = new OleDbDataAdapter("Select * from [sheet1$]", strConn);
            DataSet ds = new DataSet();
            adp.Fill(ds);
            GridView1.DataSource = ds.Tables[0].DefaultView;
            GridView1.DataBind();
        }
        else
        {
            Response.Write("只能上传excel文件!");
        }
    }
posted on 2006-11-22 22:28  月异星邪  阅读(471)  评论(0编辑  收藏  举报