コード例 #1
0
        public async Task <IActionResult> Upload()
        {
            FileInfo file = new FileInfo(@"D:\1.xlsx");

            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
            using ExcelPackage package  = new ExcelPackage(file);
            ExcelWorksheet workSheet = package.Workbook.Worksheets[0];

            int totalRows = workSheet.Dimension.Rows;

            for (int i = 2; i <= totalRows; i++)
            {
                Patient patient = new Patient
                {
                    Name      = workSheet.ConvertToString(i, 1),
                    Telephone = workSheet.ConvertToString(i, 2),
                    Gender    = workSheet.ConvertToString(i, 3) == "ذكر" ? GenderEnum.Male : GenderEnum.Female
                };
                await patientRepository.Add(patient).ConfigureAwait(true);

                await unitOfWork.CompleteAsync().ConfigureAwait(true);
            }
            return(Ok());
        }