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); }