示例#1
0
        /// <summary>
        /// ALO03_1報表_到貨配本記錄EXCEL
        /// </summary>
        /// <param name="ParameterList">變數清單</param>
        /// <returns>回傳查詢結果</returns>
        public DataTable ALO03_1(ArrayList ParameterList,
                                 ref ReportList.ExcelOtherType EOT)
        {
            #region
            ALOModel.MaintainStoreRank BCO = new ALOModel.MaintainStoreRank(ConntionDB);
            DataTable Dt = BCO.QueryStorRankForExcel2_2(GetInputValues(ParameterList));

            if (Dt != null && Dt.Rows.Count > 0)
            {
                #region 表頭:如要指定表頭必設定

                #endregion

                EOT = ReportList.ExcelOtherType.Normal;//如要匯出EXCEL此為必要設定

                return Dt;
            }
            else
            {
                throw new Exception("查無資料!!");
            }
            #endregion
        }
示例#2
0
    /// <summary>
    /// 輸出為EXCEL
    /// </summary>
    public void WriteToXls()
    {
        #region

        GridView gvExcel = new GridView();
        gvExcel.RowDataBound += new GridViewRowEventHandler(gvExcel_RowDataBound);
        try
        {
            ALOModel.MaintainStoreRank BCO = new ALOModel.MaintainStoreRank(ConnectionDB);
            DataTable dtExcel = null;
            string SessionIDName = string.Format("{0}_{1}_EXCELDATA", PAGE_DT_01, PageTimeStamp.Value);

            //匯出筆數上限
            Int32 iLimitedRowsCounts = 65535;

            if (BCO.CheckExcelOutCount(GetInputValues(), iLimitedRowsCounts))
            {

                dtExcel = BCO.QueryStorRankForExcel2_2(GetInputValues());

                if (dtExcel != null && dtExcel.Rows.Count > 0)
                {
                    Response.Clear();
                    Response.AddHeader("content-disposition", "attachment;filename=" +
                        HttpUtility.UrlEncode(txt_ExportFileName.Text.Trim().ToLower().Replace(".xls", ""), System.Text.UTF8Encoding.UTF8) + ".xls");
                    Response.ContentType = "application/vnd.ms-excel;charset='utf-8'";
                    Response.ContentEncoding = System.Text.Encoding.GetEncoding("BIG5");
                    this.EnableViewState = false;

                    System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
                    System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

                    gvExcel.AllowPaging = false;
                    gvExcel.AllowSorting = false;
                    gvExcel.DataSource = dtExcel;
                    gvExcel.DataBind();

                    gvExcel.RenderControl(oHtmlTextWriter);
                    Response.Write(oStringWriter.ToString());
                    Response.Flush();
                    Response.End();
                }
                else
                {
                    ResultMsgLabel.Text = "無匯出資料";
                }
            }
            else
            {
                throw new Exception("匯出筆數超過上限" + iLimitedRowsCounts.ToString() + "筆");
            }
        }
        catch (Exception ex)
        {
            ErrorMsgLabel.Text = ex.Message;
        }
        finally 
        {
            gvExcel.DataSource = null;
            gvExcel.Dispose();
        }

        #endregion
    }