c#将数据导出到excel中

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中

上一篇:C#发送邮件三种方法(Localhost,SMTP,SSL-SMTP)


下一篇:【转】c# 类反射简单操作