본문 바로가기

Development/.Net

ASP.NET 엑셀출력 - stoock님의 노트

반응형

ASP.NET 엑셀출력

 //-- ASP.NET에서 엑셀출력하기

   

protected void btnExcel_Click(object sender, ImageClickEventArgs e)

    {

        if (ConditionInfoDataSet.Tables["Condition"].Rows.Count > 0)

        {

            Response.Clear();

            Response.AddHeader("content-disposition", "attachment;filename=ExcelData.xls");

            Response.Charset = "";

            // If you want the option to open the Excel file without saving then

            // comment out the line below

            // Response.Cache.SetCacheability(HttpCacheability.NoCache);

            Response.ContentType = "application/vnd.xls";

            System.IO.StringWriter stringWrite = new System.IO.StringWriter();

            System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

            gvBubbleCall.RenderControl(htmlWrite);

            Response.Write(stringWrite.ToString().Replace("<td>", @"<td>=""").Replace("</td>", @"</td>"));

            Response.End();

        }

        else if (ConditionInfoDataSet.Tables["Condition"].Rows.Count <= 0)

        {

            string sScript;

            sScript = JavaScript.GetAlertScript("데이터가 없습니다.");

            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Error", sScript);

        }

    }

   

출처 : <http://stoock.springnote.com/pages/1507820>

반응형