本篇文章主要是對asp.net上傳execl文件后,在頁面上加載顯示(示例代碼)進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助
代碼如下: #region 上傳Execl文件 protected void Button1_Click(object sender, EventArgs e) { if (FileUpload1.HasFile) { string NewFileName = string.Empty; string ErrorMess = UpLoadFile(FileUpload1, ".xls|.xlsx", 1024 * 5, Server.MapPath("/Report/SocialApply/"), 1, out NewFileName); if (string.IsNullOrEmpty(ErrorMess)) { Label1.Text = "√文件上傳成功"; ViewState["UpLoadFile"] = "/Report/SocialApply/" + NewFileName; try { FileStream file = new FileStream (Server.MapPath(ViewState["UpLoadFile"] as string), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); DataTable dt1 = FairHR.Util.XmlExcelReport.ReadExcelToDataTable(file, 0, 0); ViewState.Add("ViewDT", dt1); GridView1.DataSource = ViewState["ViewDT"] as DataTable; GridView1.DataBind(); file.Close(); //Maticsoft.Common.MessageBox.ResponseScript(Page, "$.messager.alert('系統提示', '操作成功!', 'info');"); } catch { Maticsoft.Common.MessageBox.ResponseScript(Page, "$.messager.alert('系統提示', '請重新上傳Execl文件再操作', 'warning');"); } } else { Label1.Text = "×文件上傳失敗"; } } else { Label1.Text = "×請先選擇上傳文件"; } ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "idAlert1", "closeLoad();", true); } #endregion #region 上傳文件 /// <summary> /// 上傳文件 /// </summary> /// <param name="fu">上傳文件</param> /// <param name="type">上傳
|
新聞熱點
疑難解答