Monday, July 10, 2017

How to Export Basic Excel with .Net

StringBuilder sb = new StringBuilder();
sb.Append(string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\n", "STT", "Thời điểm", "Số hiệu", "Mã",
"Soos luong", "SĐT/MHĐ thụ hưởng", "Tài khoản đối ứng", "Loại bút toán"));
int i = 0;
foreach (var item in list)
{
sb.Append(string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\n", ++i, item.Time, item.code, "'" + item.Ref,
item.Amount, item.RecAccount, item.CustomerCode, item.Type));
}
Response.AddHeader("content-disposition", "attachment;filename=DoiSoatAirtime.xls");
Response.Charset = string.Empty;
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = Encoding.Unicode;
Response.BinaryWrite(Encoding.Unicode.GetPreamble());
Response.Write(sb.ToString());
Response.Flush();
Response.End();

No comments:
Write comments