Я использую MVC5 и импортирую файл Excel с помощью epplus в базу данных sql.Тем не менее, я могу импортировать файлы, которые меньше по размеру, например, менее 1000 КБ, но любой размер файла больше, чем это занимает часы, чтобы импортировать.Я ищу эффективный способ импортировать мой файл Excel в более быстрый
public ActionResult Application(FormCollection formCollection)
{
var usersList = new List<bomApplicationImportTgt>();
if (Request != null)
{
HttpPostedFileBase file = Request.Files["UploadedFile"];
if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
{
string fileName = file.FileName;
string fileContentType = file.ContentType;
byte[] fileBytes = new byte[file.ContentLength];
var data = file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength));
using (var package = new ExcelPackage(file.InputStream))
{
var currentSheet = package.Workbook.Worksheets;
var workSheet = currentSheet.First();
var noOfCol = workSheet.Dimension.End.Column;
var noOfRow = workSheet.Dimension.End.Row;
for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
{
var user = new bomApplicationImportTgt();
user.date = Convert.ToDateTime(workSheet.Cells[rowIterator, 1].Value);
user.Description = workSheet.Cells[rowIterator, 2].Value?.ToString();
user.SequenceNumber = Convert.ToInt32(workSheet.Cells[rowIterator, 3].Value);
user.PartNumber = workSheet.Cells[rowIterator, 4].Value?.ToString();
user.PartsName = workSheet.Cells[rowIterator, 5].Value?.ToString();
user.SP = workSheet.Cells[rowIterator, 6].Value?.ToString();
user.INT = workSheet.Cells[rowIterator, 7].Value?.ToString();
user.SN = workSheet.Cells[rowIterator, 8].Value?.ToString();
user.SZ = workSheet.Cells[rowIterator, 9].Value?.ToString();
user.C = workSheet.Cells[rowIterator, 10].Value?.ToString();
user.E_F = workSheet.Cells[rowIterator, 11].Value?.ToString();
user.Block = workSheet.Cells[rowIterator, 12].Value?.ToString();
user.SEC = workSheet.Cells[rowIterator, 13].Value?.ToString();
user.Item = workSheet.Cells[rowIterator, 14].Value?.ToString();
user.SUF = workSheet.Cells[rowIterator, 15].Value?.ToString();
user.Model = workSheet.Cells[rowIterator, 16].Value?.ToString();
user.M_E_F = workSheet.Cells[rowIterator, 17].Value?.ToString();
user.OP = workSheet.Cells[rowIterator, 18].Value?.ToString();
user.Type = workSheet.Cells[rowIterator, 19].Value?.ToString();
user.Quantity = workSheet.Cells[rowIterator, 20].Value?.ToString();
user.PLGRPCD = workSheet.Cells[rowIterator, 21].Value?.ToString();
user.PL1 = workSheet.Cells[rowIterator, 22].Value?.ToString();
user.ATC1 = workSheet.Cells[rowIterator, 23].Value?.ToString();
user.PL2 = workSheet.Cells[rowIterator, 24].Value?.ToString();
user.ATC2 = workSheet.Cells[rowIterator, 25].Value?.ToString();
user.PL3 = workSheet.Cells[rowIterator, 26].Value?.ToString();
user.ATC3 = workSheet.Cells[rowIterator, 27].Value?.ToString();
user.Plant = workSheet.Cells[rowIterator, 28].Value?.ToString();
user.SHR = workSheet.Cells[rowIterator, 29].Value?.ToString();
user.DC_Number = workSheet.Cells[rowIterator, 30].Value?.ToString();
user.FileName = fileName;
usersList.Add(user);
}
}
}
}
using (Dev_Purchasing_New_ModelEntities excelImportDBEntities = new Dev_Purchasing_New_ModelEntities())
{
foreach (var item in usersList)
{
excelImportDBEntities.bomApplicationImportTgts.Add(item);
}
excelImportDBEntities.SaveChanges();
}
return View("Application");
}