导入模板下载
This commit is contained in:
parent
025635e161
commit
dcca57fb9b
@ -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>
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
BIN
RIZO.Admin.WebApi/wwwroot/ImportTemplate/工艺路线导入模板.xlsx
Normal file
BIN
RIZO.Admin.WebApi/wwwroot/ImportTemplate/工艺路线导入模板.xlsx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user