优化 导入学生信息的excel转换方式
This commit is contained in:
parent
c51d219e17
commit
59fb668b98
|
|
@ -261,19 +261,8 @@ namespace Learn.Archives.API.Controllers
|
||||||
[HttpLogEnable]
|
[HttpLogEnable]
|
||||||
public async Task<IActionResult> Import(IFormFile? file)
|
public async Task<IActionResult> Import(IFormFile? file)
|
||||||
{
|
{
|
||||||
|
var dataList = await _httpContextAccessor.ParsingExcelAsync<StudentInfoImportError>();
|
||||||
var fl = file != null ? file : _httpContextAccessor.HttpContext?.Request.Form.Files[0];
|
dataList = dataList.Where(s => !string.IsNullOrEmpty(s.School)).ToArray();
|
||||||
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));
|
|
||||||
}
|
|
||||||
if (dataList == null || dataList.Count() == 0)
|
if (dataList == null || dataList.Count() == 0)
|
||||||
Oh.ModelError("导入失败:无有效数据");
|
Oh.ModelError("导入失败:无有效数据");
|
||||||
var insertInfo = new List<Student>();
|
var insertInfo = new List<Student>();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue