public async Task Import_Test() { IExcelImporter Importer = new ExcelImporter(); var filePath = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles", "Import", "issue236.xlsx"); using (var stream = new FileStream(filePath, FileMode.Open)) { var result = await Importer.Import <Issue236>(stream); Importer.OutputBussinessErrorData <Issue236>(filePath, result.RowErrors.ToList(), out var msg); } }
public async Task <ImportResultDto> ImportExcel(ImportExcelInput input) { IExcelImporter Importer = new ExcelImporter(); var stream = new MemoryStream(input.Bytes); var import = await Importer.Import <ArticleImportDto>(stream); var result = new ImportResultDto { HasError = import.HasError, RowErrors = import.RowErrors, TemplateErrors = import.TemplateErrors, }; if (import.RowErrors != null && import.RowErrors.Count > 0) { var newStream = new MemoryStream(stream.ToArray()); Importer.OutputBussinessErrorData <ArticleImportDto>(newStream, import.RowErrors.ToList(), out byte[] fileByte); var createFileOutput = await _fileService.CreateAsync(new CreateFileInput { FileContainerName = FileContainerNameConsts.Temp, FileName = input.FileName, MimeType = input.MimeType, FileType = FileType.RegularFile, ParentId = null, OwnerUserId = CurrentUser.Id, Content = fileByte }); result.ErrorFile = createFileOutput; return(result); } var entitys = ObjectMapper.Map <List <ArticleImportDto>, List <Article> >(import.Data.ToList()); await _repository.InsertManyAsync(entitys); return(result); }