From 82e4d556643136cf6efcc1cbcfea1226a3f9f074 Mon Sep 17 00:00:00 2001 From: quowingwang Date: Thu, 18 Dec 2025 15:01:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E5=8D=95=E5=AF=BC=E5=85=A5=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Admin.WebApi/Controllers/BaseController.cs | 18 ++++++++++++++++++ .../mes/pro/ProWorkorderV2Controller.cs | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ZR.Admin.WebApi/Controllers/BaseController.cs b/ZR.Admin.WebApi/Controllers/BaseController.cs index a2cdc0d5..b58baf89 100644 --- a/ZR.Admin.WebApi/Controllers/BaseController.cs +++ b/ZR.Admin.WebApi/Controllers/BaseController.cs @@ -68,7 +68,25 @@ namespace ZR.Admin.WebApi.Controllers // return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileName); } + protected IActionResult ExportExcel2(string path, string fileName) + { + if (!Path.Exists(path)) + { + throw new CustomException(fileName + "文件不存在"); + } + var stream = Io.File.OpenRead(path); + + // 设置响应头 + Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition"); + + // 对文件名进行编码(使用RFC 5987标准) + var encodedFileName = Uri.EscapeDataString(fileName); + Response.Headers.Add("Content-Disposition", + $"attachment; filename*=UTF-8''{encodedFileName}"); + + return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + } #region 方法 /// diff --git a/ZR.Admin.WebApi/Controllers/mes/pro/ProWorkorderV2Controller.cs b/ZR.Admin.WebApi/Controllers/mes/pro/ProWorkorderV2Controller.cs index 6707adde..16b471f6 100644 --- a/ZR.Admin.WebApi/Controllers/mes/pro/ProWorkorderV2Controller.cs +++ b/ZR.Admin.WebApi/Controllers/mes/pro/ProWorkorderV2Controller.cs @@ -59,7 +59,7 @@ namespace ZR.Admin.WebApi.Controllers.mes.pro public IActionResult ImportTemplateExcel() { (string, string) result = DownloadImportTemplate("日生产计划模板");//返回文件名和路径 - return ExportExcel(result.Item2, result.Item1); + return ExportExcel2(result.Item2, result.Item1); }