标签:
ds为数据源
Response.Buffer = true;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + FileName); //文件名
Response.ContentType = "application/ms-excel";
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
DataGrid dg = new DataGrid();
dg.DataSource = ds;
dg.DataBind();
dg.RenderControl(htmlWrite);
Response.Write("<meta http-equiv=Content-Type content=text/html;charset=utf-8>"); //处理乱码
Response.Write(stringWrite.ToString()); //写缓冲区中的数据到HTTP头文件中
Response.End();
标签:
原文地址:http://www.cnblogs.com/changyehppy/p/4244616.html