Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=" + DateTime.Now.ToString("yyyy-MM-dd") + ".csv");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.ContentType = "application/excel";
var sb = new StringBuilder();
sb.Append("姓名,工号,性别,部门\r\n");
foreach (var item in query)
{
sb.Append("\"" + item.Name + "\"" + ",");
sb.Append("\"" + item.Code + "\"" + ",");
sb.Append("\"" + item.Sex + "\"" + ",");
sb.Append("\"" + item.deptName + "\"" + ",");
}
Response.Write(sb.ToString());
Response.End();
C# 导出CSV