导入模板下载

This commit is contained in:
quowingwang 2025-11-11 14:43:27 +08:00
parent 025635e161
commit dcca57fb9b
3 changed files with 23 additions and 1 deletions

View File

@ -9,6 +9,7 @@ using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Web;
@ -72,9 +73,18 @@ namespace Infrastructure.Controllers
throw new CustomException(fileName + "文件不存在");
}
var stream = System.IO.File.OpenRead(path); //创建文件流
//Response.Headers.Append("Access-Control-Expose-Headers", "Content-Disposition");
//return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", HttpUtility.UrlEncode(fileName));
// 1. 对中文文件名进行 UTF-8 编码(处理空格为 %20
string encodedFileName = HttpUtility.UrlEncode(fileName, Encoding.UTF8).Replace("+", "%20");
// 2. 设置标准响应头(关键:告知浏览器文件名使用 UTF-8 编码)
Response.Headers.Append("Access-Control-Expose-Headers", "Content-Disposition");
return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", HttpUtility.UrlEncode(fileName));
Response.Headers["Content-Disposition"] = $"attachment; filename*=UTF-8''{encodedFileName}";
// 3. 返回文件流(不使用 File 方法的第三个参数,避免重复编码)
return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
/// <summary>

View File

@ -182,6 +182,18 @@ namespace RIZO.Admin.WebApi.Controllers.Mes.Process
);
}
/// <summary>
/// 工艺信息导入模板下载
/// </summary>
/// <returns></returns>
[HttpGet("importTemplate")]
[Log(Title = "工艺路线导入模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = true, IsSaveResponseData = false)]
[AllowAnonymous]
public IActionResult ImportTemplateExcel()
{
(string, string) result = DownloadImportTemplate("工艺路线导入模板");
return ExportExcel(result.Item2, result.Item1);
}
}
}