RT
代码:
protected void btnReport_Click(object sender, EventArgs e) { IList<Member> StudentList = Search(); string data = ExportCSV(StudentList); string temp = string.Format("attachment;filename={0}", DateTime.Now.ToString("yyyyMMddHHmmss") + ".csv"); Response.ClearHeaders(); Response.AppendHeader("Content-disposition", temp); Response.HeaderEncoding = Encoding.GetEncoding("shift-jis"); Response.ContentType = "application/octet-stream"; Response.ContentEncoding = Encoding.GetEncoding("shift-jis"); Response.Write(data); Response.Flush(); Response.Close(); IsReport = false; } public string ExportCSV(IList<Member> list) { string data = ""; data = "First name,Last name,DOB,Email,Phone number,Gender,Points,Rank,Address,Suburb,Postcode,School,Avatar Name,Username,Password,DataCreated,Activated status\n"; foreach (Member tb in list) { data += "\"" + tb.FirstName + "\"," + "\"" + tb.LastName + "\"," + "\"" + tb.DateOfBirth + "\"," + "\"" + tb.Email + "\"," + "\"" + tb.PhoneNumber + "\"," + "\"" + (tb.Gender == "F" ? "Female" : (tb.Gender == "M" ? "Male" : "")) + "\"," + "\"" + tb.Points + "\"," + "\"" + (tb.Rank == null ? "" : tb.Rank.Name) + "\"," + "\"" + tb.Address + "\"," + "\"" + tb.Suburb + "\"," + "\"" + tb.Postcode + "\"," + "\"" + (tb.School == null ? "" : tb.School.Name) + "\"," + "\"" + tb.Nickname + "\"," + "\"" + tb.Username + "\"," + "\"" + tb.Password + "\"," + "\"" + tb.DateCreated + "\"," + "\"" + tb.IsActive + "\"," + "\n"; } return data; }
函数式编程
Helenr
海绵宝宝撒
白猪掌柜的
繁星点点滴滴