/// <summary> /// ALO25_1報表_列印鈕 /// </summary> /// <param name="ParameterList">變數清單</param> /// <param name="ReportOutputFormat">報表格式(PDF,EXCEL)</param> /// <returns>回傳查詢結果</returns> public DataTable ALO25_1(ArrayList ParameterList, ref ReportList.ExcelOtherType EOT ) { #region ALOModel.VDS_ALO25_BCO BCO = new ALOModel.VDS_ALO25_BCO(ConntionDB); DataTable Dt = null; Dt = BCO.QueryForALO25(ParameterList); if (Dt == null || Dt.Rows.Count == 0) { throw new Exception("查無資料"); } return Dt; #endregion }
/// <summary> /// 輸出為EXCEL /// </summary> public void WriteToXls() { #region try { #region ALOModel.VDS_ALO25_BCO BCO = new ALOModel.VDS_ALO25_BCO(ConnectionDB); DataTable dt = null; dt = BCO.QueryForALO25(GetQueryParams()); if (dt == null || dt.Rows.Count <= 0) { throw new Exception("查無資料"); } #endregion #region Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode("不貼標商品報表", System.Text.UTF8Encoding.UTF8) + ".xls"); Response.ContentType = "application/vnd.ms-excel;charset='utf-8'"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); this.EnableViewState = false; System.IO.StringWriter oStringWriter = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter); gv_Export.DataSource = dt; gv_Export.DataBind(); gv_Export.RenderControl(oHtmlTextWriter); Response.Write(oStringWriter.ToString()); Response.Flush(); Response.End(); #endregion } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } finally { gv_Export.DataSource = null; gv_Export.DataBind(); } #endregion }