using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using WalkingTec.Mvvm.Core; namespace WalkingTec.Mvvm.Mvc { public static class FileExtension { /// /// 生成下载文件 /// /// /// /// /// public static FileContentResult GetExportData(this IBasePagedListVM self, string ExportName = "") where T : TopBasePoco, new() { self.SearcherMode = self.Ids != null && self.Ids.Count > 0 ? ListVMSearchModeEnum.CheckExport : ListVMSearchModeEnum.Export; var data = self.GenerateExcel(); string ContentType = self.ExportExcelCount > 1 ? "application/x-zip-compresse" : "application/vnd.ms-excel"; ExportName = string.IsNullOrEmpty(ExportName) ? typeof(T).Name : ExportName; ExportName = self.ExportExcelCount > 1 ? $"Export_{ExportName}_{DateTime.Now.ToString("yyyyMMddHHmmssffff")}.zip" : $"Export_{ExportName}_{DateTime.Now.ToString("yyyyMMddHHmmssffff")}.xlsx"; FileContentResult Result = new FileContentResult(data, ContentType); Result.FileDownloadName = ExportName; return Result; } } }