Ejemplo n.º 1
0
 public StreamReaderTest()
 {
     _file = new FileStream(@"C:\Users\IdaBagusLeo\Documents\Spesialist.xlsx",
                            FileMode.Open, FileAccess.Read);
     StreamAdvanceOption _options = new StreamAdvanceOption()
     {
         FirstRowAsColumnName = true
     };
 }
Ejemplo n.º 2
0
        public List <T> ImportData <T>(IFormFile file, StreamAdvanceOption option = null) where T : class, IStreamEntity, new()
        {
            if (file != null)
            {
                Stream stream = file.OpenReadStream();

                var builder = new AdvanceStreamBuilder <T>(option);
                return(builder.CreateReader(Path.GetExtension(file.FileName)).Read(stream));
            }
            else
            {
                throw new FieldAccessException("Failed accessed file");
            }
        }
Ejemplo n.º 3
0
        public IActionResult ImportData()
        {
            //read all uploaded file
            IFormFileCollection files = Request.Form.Files;

            if (files.Count > 0)
            {
                //set option for how to read file
                StreamAdvanceOption option =
                    new StreamAdvanceOption(firstRowAsColumnName: true);


                try
                {
                    //get the first file and extract the data
                    //with spesific class
                    IFormFile file = files.FirstOrDefault();
                    IList <SpecialistExcelEntity> result = _fileService
                                                           .ImportData <SpecialistExcelEntity>(file, option);

                    //fetch data into model
                    List <MedicalStaffSpecialistModel> importedData = new List <MedicalStaffSpecialistModel>();
                    foreach (SpecialistExcelEntity en in result)
                    {
                        importedData.Add(new MedicalStaffSpecialistModel
                        {
                            Name        = en.Name,
                            Description = en.Description,
                            Alias       = en.Alias
                        });
                    }
                    //insert
                    _medicalSpecialistService.CreateRange(importedData);
                    return(Ok(result));
                }catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
            }
            else
            {
                return(BadRequest("File not found"));
            }
        }
Ejemplo n.º 4
0
 public ExcelStreamReader(string type, StreamAdvanceOption options)
 {
     this.type    = type;
     this.options = options;
 }
Ejemplo n.º 5
0
 public AdvanceStreamBuilder()
 {
     _options = SetDefaulOptions();
 }
Ejemplo n.º 6
0
 public AdvanceStreamBuilder(StreamAdvanceOption options)
 {
     _options = options;
 }