상세 컨텐츠

본문 제목

grid 내용을 엑셀로 내보내기

C#

by happynuri 2008. 5. 13. 09:22

본문

private void Button1_Click(object sender, System.EventArgs e)
  {
   //엑셀로 저장
   Response.Clear();
   Response.AddHeader("content-disposition", "attachment;filename=Question_full.xls");
   Response.ContentType = "application/vnd.xls";

   System.IO.StringWriter stringWriter = new System.IO.StringWriter();
   stringWriter.WriteLine("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ks_c_5601-1987\">");
   System.Web.UI.HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
   DataGrid1.RenderControl(htmlWriter);

   Response.Write(stringWriter.ToString());
   Response.End();
  }

관련글 더보기

댓글 영역