码迷,mamicode.com
首页 > 其他好文 > 详细

导出Excel事例

时间:2016-04-28 13:59:05      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

 DataTable table = new DataTable();

StringWriter sw = new StringWriter();

string tabltitle = "客户名称,电话号码,导入时间,分组编号,透传号码,预测状态";//excel表头
sw.WriteLine(tabltitle);

foreach (DataRow dr in table.Rows)
{
string tempstr = dr[0].ToString().Replace(",", "-") + "," + dr[1].ToString().Replace(",", "-") + ",";
tempstr += dr[2].ToString().Replace(",", "-") + ",";
tempstr += dr[3].ToString().Replace(",", "-") + ",";
tempstr += dr[4].ToString().Replace(",", "-") + ",";
tempstr += dr[5].ToString().Replace(",", "-");
sw.WriteLine(tempstr);
}
sw.Close();
Response.AddHeader("Content-Disposition", "attachment; filename=FORECASTInfoBackup.csv");
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Write(sw);
Response.End();

导出Excel事例

标签:

原文地址:http://www.cnblogs.com/chj929555796/p/5442270.html

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