码迷,mamicode.com
首页 > Web开发 > 详细

asp.net导出excel较为简约的代码

时间:2015-01-23 18:03:47      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

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();

asp.net导出excel较为简约的代码

标签:

原文地址:http://www.cnblogs.com/changyehppy/p/4244616.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!