标签:
/// <summary> /// 写入ecexl /// </summary> /// <param name="dt"></param> /// <param name="FileName"></param> public static void CreateExcel(DataTable dt, string FileName) { HttpResponse resp = HttpContext.Current.Response; resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); resp.AppendHeader("Content-Disposition", "attachment;filename=" + FileName + ".xls"); string colHeaders = string.Empty; string ls_item = string.Empty; DataRow[] myRow = dt.Select(); int cl = dt.Columns.Count; for (int i = 0; i < cl; i++) { if (i < 4) { if (i == 3) { colHeaders += dt.Columns[i].Caption.ToString() + "\n"; } else { colHeaders += dt.Columns[i].Caption.ToString() + "\t"; } } } resp.Write(colHeaders); foreach (DataRow dr in myRow) { for (int j = 0; j < cl; j++) { if (j < 4) { if (j == 3) { ls_item += Hostname2ip(dr[j - 1].ToString()) + "\n"; } else { ls_item += dr[j].ToString() + "\t"; } } } } resp.Write(ls_item); ls_item = string.Empty; resp.End(); }
标签:
原文地址:http://www.cnblogs.com/Aamir-Ye/p/4571607.html