浏览代码

update Admin.NET/Admin.NET.Core/Util/CommonUtil.cs.
导出模板Excel、导出数据excel方法支持传入文件名导出文件,不传入用类型名称作为导出文件名

Signed-off-by: LLL <422235757@qq.com>

LLL 2 年之前
父节点
当前提交
3ded995985
共有 1 个文件被更改,包括 4 次插入4 次删除
  1. 4 4
      Admin.NET/Admin.NET.Core/Util/CommonUtil.cs

+ 4 - 4
Admin.NET/Admin.NET.Core/Util/CommonUtil.cs

@@ -104,24 +104,24 @@ public static class CommonUtil
     /// 导出模板Excel
     /// </summary>
     /// <returns></returns>
-    public static async Task<IActionResult> ExportExcelTemplate<T>() where T : class, new()
+    public static async Task<IActionResult> ExportExcelTemplate<T>(string fileName = null) where T : class, new()
     {
         IImporter importer = new ExcelImporter();
         var res = await importer.GenerateTemplateBytes<T>();
 
-        return new FileContentResult(res, "application/octet-stream") { FileDownloadName = typeof(T).Name + ".xlsx" };
+        return new FileContentResult(res, "application/octet-stream") { FileDownloadName = $"{(string.IsNullOrEmpty(fileName) ? typeof(T).Name : fileName)}.xlsx" };
     }
 
     /// <summary>
     /// 导出数据excel
     /// </summary>
     /// <returns></returns>
-    public static async Task<IActionResult> ExportExcelData<T>(ICollection<T> data) where T : class, new()
+    public static async Task<IActionResult> ExportExcelData<T>(ICollection<T> data, string fileName = null) where T : class, new()
     {
         var export = new ExcelExporter();
         var res = await export.ExportAsByteArray<T>(data);
 
-        return new FileContentResult(res, "application/octet-stream") { FileDownloadName = typeof(T).Name + ".xlsx" };
+        return new FileContentResult(res, "application/octet-stream") { FileDownloadName = $"{(string.IsNullOrEmpty(fileName) ? typeof(T).Name : fileName)}.xlsx" };
     }
 
     /// <summary>