using FineUIPro; using iWareExcel.EXCEL.Entity; using iWareExcel.Utils; using System.Collections.Generic; using System.IO; using System.Text; using System.Web; namespace iWareWms.Code.Excel.Service { /// /// Excel服务 /// public class ExcelService { private static object Lock = new object(); private ExcelService() { } private static ExcelService Instance = null; /// /// 获取单例的方法 /// /// 菜单服务的单例实体 public static ExcelService GetInstance() { if (Instance == null) { lock (Lock) { if (Instance == null) { Instance = new ExcelService(); } } } return Instance; } public string ToExcel(WorkBookEntity workBook, Dictionary> datas, out string msg) { var path = ExcelHelper.ToExcelByEPPlus(workBook, datas, out msg); if (!string.IsNullOrEmpty(msg)) { Alert.ShowInTop(msg); return ""; } return path; } public string ToExcelByEPPlus(WorkBookEntity workBook, Dictionary> datas, out string msg) { var path = ExcelHelper.ToExcelByEPPlus(workBook, datas, out msg); if (!string.IsNullOrEmpty(msg)) { Alert.ShowInTop(msg); return ""; } return path; } public void OutputClient(FileInfo file) { HttpResponse response = HttpContext.Current.Response; response.Buffer = true; response.Clear(); response.ClearHeaders(); response.ClearContent(); //导出到 .xlsx 格式不能用时,可以试试这个 HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", file.Name)); response.Charset = "GB2312"; response.ContentEncoding = Encoding.GetEncoding("GB2312"); response.AddHeader("Content-Length", file.Length.ToString()); response.WriteFile(file.FullName); response.Flush(); response.Close(); } } }