From 59fb668b98c608a4dcc89abf4046c11dcec31505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=82=A5=E7=BE=8A?= <1048382248@qq.com> Date: Tue, 2 Dec 2025 10:01:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E5=AD=A6=E7=94=9F=E4=BF=A1=E6=81=AF=E7=9A=84excel=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/StudentController.cs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/Learn.Archives.API/Controllers/StudentController.cs b/Learn.Archives.API/Controllers/StudentController.cs index 0ed1d5a..616ffb8 100644 --- a/Learn.Archives.API/Controllers/StudentController.cs +++ b/Learn.Archives.API/Controllers/StudentController.cs @@ -261,19 +261,8 @@ namespace Learn.Archives.API.Controllers [HttpLogEnable] public async Task 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 dataList; - using var stream = new MemoryStream(); - { - await fl.CopyToAsync(stream); - dataList = stream.Query() - .Where(s => !string.IsNullOrEmpty(s.School)); - } + var dataList = await _httpContextAccessor.ParsingExcelAsync(); + dataList = dataList.Where(s => !string.IsNullOrEmpty(s.School)).ToArray(); if (dataList == null || dataList.Count() == 0) Oh.ModelError("导入失败:无有效数据"); var insertInfo = new List();