2009年8月21日 星期五

C# 匯出WORD檔案

Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=test.doc");//word檔名
Response.ContentType = "application/vnd.ms-word";
Response.Charset = "";
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
DataGrid dg = new DataGrid();
dg.DataSource = this.SqlDataSource1.Select(DataSourceSelectArguments.Empty);
dg.DataBind();
dg.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();

沒有留言:

張貼留言