优化 导入学生信息的excel转换方式

This commit is contained in:
小肥羊 2025-12-02 10:01:52 +08:00
parent c51d219e17
commit 59fb668b98
1 changed files with 2 additions and 13 deletions

View File

@ -261,19 +261,8 @@ namespace Learn.Archives.API.Controllers
[HttpLogEnable]
public async Task<IActionResult> Import(IFormFile? file)
{
var fl = file != null ? file : _httpContextAccessor.HttpContext?.Request.Form.Files[0];
if (fl == null) Oh.ModelError("传入无效的数据");
if (!Path.GetExtension(fl.FileName).Equals(".xlsx", StringComparison.OrdinalIgnoreCase))
Oh.ModelError("请选择导入文件为.xlsx的后缀名!");
//分析excel
IEnumerable<StudentInfoImportError> dataList;
using var stream = new MemoryStream();
{
await fl.CopyToAsync(stream);
dataList = stream.Query<StudentInfoImportError>()
.Where(s => !string.IsNullOrEmpty(s.School));
}
var dataList = await _httpContextAccessor.ParsingExcelAsync<StudentInfoImportError>();
dataList = dataList.Where(s => !string.IsNullOrEmpty(s.School)).ToArray();
if (dataList == null || dataList.Count() == 0)
Oh.ModelError("导入失败:无有效数据");
var insertInfo = new List<Student>();