首页 > Windows开发 > 详细

c#将数据导出到excel中

时间:2014-11-11 12:13:23      阅读:200      评论:0      收藏:0      [点我收藏+]

DataTable   dt = new BLL.T_Expiry().GetAllList().Tables[0];//查询数据

string FileName = "T_Users.xls";

HttpResponse response = Page.Response;

response.AppendHeader("Content-Disposition", "attachment;filename=" + FileName);
Response.ContentType = "application/ms-excel";
response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");

foreach (DataColumn dc in dt.Columns)
{
response.Write(dc.ColumnName + "\t");
}

response.Write("\n");

foreach (DataRow dr in dt.Rows)
{
for (int i = 0; i < dt.Columns.Count; i++)
{
response.Write(dr[i].ToString() + "\t");
}

response.Write("\n");
}

response.End();

c#将数据导出到excel中

原文:http://www.cnblogs.com/apes-monkeys/p/4088894.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!