国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

DataTable內(nèi)容導(dǎo)出為CSV文件

2019-11-17 02:20:52
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

DataTable內(nèi)容導(dǎo)出為CSV文件

CSVHelper.cs內(nèi)容:

  1 using System;  2 using System.Collections.Generic;  3 using System.Linq;  4 using System.Text;  5 using System.Web;  6 using System.Threading;  7 using System.IO;  8 using System.Data;  9 using System.Windows.Forms; 10  11 namespace IMSCommonFunction 12 { 13     public class CSVHelper 14     { 15         public static string FilterCSVCell(string cellContent) 16         { 17             bool isAddFlag = false; 18             if (cellContent.IndexOf("/"") != -1) 19             { 20                 cellContent = cellContent.Replace("/"", "/"/""); 21                 cellContent = "/"" + cellContent + "/""; 22                 isAddFlag = true; 23             } 24             if (cellContent.IndexOf(",") != -1 && isAddFlag != true) 25             { 26                 cellContent = "/"" + cellContent + "/""; 27             } 28             return cellContent; 29         } 30  31         public static void ExportCSVFile(HttPResponse response, string fullPath, string Content) 32         { 33             try 34             { 35                 response.Buffer = true; 36                 response.Clear(); 37                 response.Charset = System.Text.Encoding.Default.BodyName; 38                 response.ContentEncoding = System.Text.Encoding.UTF8;// System.Text.Encoding.GetEncoding("GB2312");//GB2312用Excel打開(kāi)時(shí),沒(méi)有亂碼。 39                 response.AppendHeader("Content-Disposition", "attachment;filename=" + fullPath); 40                 response.ContentType = "application/ms-excel"; 41                 response.Output.Write(Content); 42                 response.Flush(); 43                 response.End(); 44             } 45             catch (ThreadAbortException) 46             { 47             } 48             catch (Exception ex) 49             { 50                 throw new ApplicationException(string.Format("Export CSV file have a error: {0}", fullPath), ex); 51             } 52         } 53  54         public static void FileDownload(string FullFileName) 55         { 56             FileInfo DownloadFile = new FileInfo(FullFileName); 57             System.Web.HttpContext.Current.Response.Clear(); 58             System.Web.HttpContext.Current.Response.ClearHeaders(); 59             System.Web.HttpContext.Current.Response.Buffer = false; 60             string extension = Path.GetExtension(FullFileName); 61             extension = string.IsNullOrEmpty(extension) ? extension : extension.ToLower(); 62             switch (extension) 63             { 64                 case ".xml": 65                     System.Web.HttpContext.Current.Response.ContentType = "text/xml"; 66                     break; 67                 default: 68                     System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream"; 69                     break; 70             } 71             string browser = System.Web.HttpContext.Current.Request.UserAgent.ToUpper(); 72             bool isNeedEncode = !browser.Contains("Firefox"); 73             System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + 74                 (isNeedEncode ? System.Web.HttpUtility.UrlEncode(DownloadFile.Name, System.Text.Encoding.UTF8) : DownloadFile.Name)); 75             System.Web.HttpContext.Current.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString()); 76             System.Web.HttpContext.Current.Response.Flush(); 77             if (System.Web.HttpContext.Current.Response.IsClientConnected) 78                 System.Web.HttpContext.Current.Response.WriteFile(DownloadFile.FullName); 79  80             //出錯(cuò) 81             System.Web.HttpContext.Current.Response.End(); 82             System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest(); 83         } 84  85         public static void DataHtmlToExcel(HttpResponse response, DataTable dt, string strFileName) 86         { 87             string style = @"<style> .text { mso-number-format:/@; } </scr
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 百色市| 乌苏市| 枣庄市| 郑州市| 平山县| 沾化县| 舞钢市| 台山市| 察雅县| 根河市| 和林格尔县| 仲巴县| 郁南县| 金川县| 东莞市| 松江区| 饶阳县| 瑞丽市| 涡阳县| 彰化市| 保康县| 安康市| 南丰县| 甘孜| 孝义市| 湘乡市| 罗平县| 礼泉县| 独山县| 文山县| 荣成市| 顺昌县| 商都县| 纳雍县| 绵阳市| 尚义县| 林口县| 上蔡县| 仁布县| 高唐县| 林口县|