protected void Page_Load(object sender, EventArgs e) { try { #region 清空Message this.ErrorMsgLabel.Text = string.Empty; this.RightMsgLabel.Text = string.Empty; #endregion if (!IsPostBack) { #region Attributes this.but_Close.Attributes["onclick"] += "window.close();"; #endregion #region 取得異常資料 #region 傳入參數 ParameterList.Clear(); ParameterList.Add(Session["UID"].ToString()); ParameterList.Add("2"); #endregion #region 連結資料庫 VAMModel.ProcessVAMMonthClose BCO = new VAMModel.ProcessVAMMonthClose(ConntionDB); DataTable dt_Return = BCO.QueryTmp(ParameterList); #endregion #region 檢查回傳資料 if (dt_Return.Rows.Count == 0) { this.ErrorMsgLabel.Text = "查無資料"; return; } else { this.gv_Result.DataSource = dt_Return; this.gv_Result.DataBind(); } #endregion #endregion } } catch (Exception ex) { WaringLogProcess(ex.Message); this.ErrorMsgLabel.Text = ex.Message; } finally { } }
private void ExportUnusual_Excel() { try { ParameterList.Clear(); ParameterList.Add(Session["UID"].ToString()); ParameterList.Add("2"); BCO.ProcessVAMMonthClose bco = new BCO.ProcessVAMMonthClose(ConntionDB); DataTable dt_Return = bco.QueryTmp(ParameterList); if (dt_Return.Rows.Count == 0) { this.ErrorMsgLabel.Text = "查無資料"; return; } ExcelXmlWorkbook book = new ExcelXmlWorkbook(); Worksheet sheet0 = book[0]; AddSheetData(ref sheet0, "Sheet1", dt_Return); //設定輸出檔名 string s_FileName = s_FileName = HttpUtility.UrlEncode("VAM03_供應商合約補收異常報表.XLS", System.Text.Encoding.UTF8); //File download Response.Charset = "big5"; Response.ContentType = "application/x-excel;charset='utf-8'"; Response.AddHeader("content-disposition", "attachment; filename=" + s_FileName);//excel檔名 System.IO.MemoryStream stream = new System.IO.MemoryStream(); book.Export(stream); string producedExcel = GetStringFromMemoryStream(stream); stream.Close(); Response.Write(producedExcel); Response.Flush(); Response.End(); } catch (Exception ex) { ErrorMsgLabel.Text = ex.ToString(); } finally { } }