티스토리 툴바


'excel'에 해당되는 글 1건

  1. 2010/11/12 repeater Excel download


리피터 엑셀 다운로드
 public void RptToExcel(System.Web.UI.WebControls.Repeater repeater, string filename)
 {
        repeater.EnableViewState = false;

        System.IO.StringWriter sw= new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
        repeater.RenderControl(hw);

        ExportExcel(sw, filename);
 }
private void ExportExcel(System.IO.StringWriter sw, string filename)
{
        Response.ContentType = "application/vnd.ms-excel";
        Response.AddHeader("Content-Disposition", "attachment;filename="
        + string.Concat(DateTime.Now.ToString("yyyyMMddHHmmss"), ".xls"));
        Response.Charset = "ks_c_5601-1987";
        string data = @"<html><head><style>.text {mso-number-format:\@;} </style>
       <meta http-equiv='content-type' content='text/html; charset=utf-8'></head><body>";
       data += System.Text.RegularExpressions.Regex.Replace(sw.ToString(), "&nbsp;", " ");
        data += "</body></html>";

        Response.Write(data);
        Response.End();
}


rptExcel.DataSource = ds.Tables[0];
rptExcel.DataBind();
rptExcel.Visible = true;
RptToExcel(rptExcel, "name.xls");
rptExcel.Visible = false;

'정리없는자료 > .NET' 카테고리의 다른 글

ASP.NET ( C# ) Socket 통신, w3Sockets  (0) 2011/04/21
IIS7.x에서 파일 업로드 용량 변환  (0) 2010/11/12
repeater Excel download  (0) 2010/11/12
Repeater FooterTemplate  (0) 2010/11/12
ASP.NET 특정 일자를 가감  (0) 2008/10/15
ASP.NET 정상적인 일자인지를 체크  (0) 2008/10/15

top

Trackback Address :: http://deuxist.tistory.com/trackback/493 관련글 쓰기

Write a comment