优化 导入学生信息的excel转换方式
This commit is contained in:
parent
c51d219e17
commit
59fb668b98
|
|
@ -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>();
|
||||
|
|
|
|||
Loading…
Reference in New Issue