日期:2014-05-17 浏览次数:21089 次
public void DataSetToExcel(DataTable dt)
{
HttpResponse resp = HttpContext.Current.Response;
resp.Clear();
resp.AppendHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode("application / vnd.ms - excel", System.Text.Encoding.UTF8) + "\"");
resp.ContentType = "application/ms-excel;";
//resp.ContentEncoding = Encoding.GetEncoding("GB2312");
resp.ContentType = "application/vnd.ms-excel";
resp.AppendHeader("Content-Disposition", "attachment;filename=Excel.cvs");
StringWriter oSW = new StringWriter();
HtmlTextWriter oHW = new HtmlTextWriter(oSW);
DataGrid dg = new DataGrid();
dg.DataSource = dt;
dg.DataBind();
dg.RenderControl(oHW);
resp.Write(oSW.ToString());
resp.Flush();
resp.Close();
}