public IActionResult SpreadsheetConvertTo(ExcelDokModel model) { try { Workbook workbook = new Workbook(); string fPath = Path.Combine(VratiGlavnaFolder()); DirectoryInfo d = new DirectoryInfo(fPath); string Uvoznik = "00000" + HttpContext.Session.GetObjectFromJson <KorisnikModel>("LogovaniKorisnik").Uvoznik.AutoID.ToString(); Uvoznik = Uvoznik.Substring(Uvoznik.Length - 5, 5); FileInfo[] files = d.GetFiles(Uvoznik + "_*").OrderByDescending(c => c.LastWriteTime).ToArray(); if (files.Length > 0) { string fajl = files[0].FullName; workbook.LoadDocument(fajl); Worksheet ws = workbook.Worksheets["Tipovi"]; int BrojRedova = GetEmptyCellRowIndex(ws) - 4; //string m = ws.Cells["M7"].Value.ToString(); GlavnaDAO.DeleteExcelImport(HttpContext.Session.GetObjectFromJson <KorisnikModel>("LogovaniKorisnik")); ExcelImpoortRow ExcelRed; for (int i = 4; i < GetEmptyCellRowIndex(ws); i++) { ExcelRed = new ExcelImpoortRow(); ExcelRed.UvoznikID = HttpContext.Session.GetObjectFromJson <KorisnikModel>("LogovaniKorisnik").Uvoznik.AutoID; ExcelRed.KorisnikID = HttpContext.Session.GetObjectFromJson <KorisnikModel>("LogovaniKorisnik").Id; ExcelRed.Fajl = fajl; ExcelRed.RedBr = (i - 3).ToString(); ExcelRed.Naziv = VratiStr(ws.Cells["B" + i.ToString()].Value.ToString()); ExcelRed.VrstaHomologacijeID = VratiStr(ws.Cells["B" + i.ToString()].Value.TextValue.Substring(0, 3)); ExcelRed.Marka = VratiStr(ws.Cells["C" + i.ToString()].Value.ToString()); ExcelRed.Tip = VratiStr(ws.Cells["D" + i.ToString()].Value.ToString()); ExcelRed.HOznaka = VratiStr(ws.Cells["E" + i.ToString()].Value.ToString()); ExcelRed.PolozajHOznake = VratiStr(ws.Cells["F" + i.ToString()].Value.ToString()); ExcelRed.Proizvodjac = VratiStr(ws.Cells["G" + i.ToString()].Value.ToString()); ExcelRed.ProizvodjacAdresa = VratiStr(ws.Cells["H" + i.ToString()].Value.ToString()); ExcelRed.KomNazivTipa = VratiStr(ws.Cells["I" + i.ToString()].Value.ToString()); ExcelRed.Oznaka = VratiStr(ws.Cells["J" + i.ToString()].Value.ToString()); ExcelRed.PolozajOznake = VratiStr(ws.Cells["K" + i.ToString()].Value.ToString()); ExcelRed.Namjena = VratiStr(ws.Cells["L" + i.ToString()].Value.ToString()); ExcelRed.Napomena = VratiStr(ws.Cells["M" + i.ToString()].Value.ToString()); ExcelRed.Link = VratiStr(ws.Cells["N" + i.ToString()].Value.TextValue); try { GlavnaDAO.CreateNewExcelRed(ExcelRed); } catch (SqlException) { ViewBag.ErrorMessages = "Greška se nalazi u " + ExcelRed.RedBr + ". redu u excel fajlu! Molim Vas popravite excel fajl!"; workbook.Dispose(); return(View("Index")); } } workbook.Dispose(); ViewBag.ErrorMessages = GlavnaDAO.CallExcelProcedure(HttpContext.Session.GetObjectFromJson <KorisnikModel>("LogovaniKorisnik")).Replace("\n", "<br/>"); } } catch (Exception) { //ViewBag.ErrorMessages = "Nije ispravan format unešenog fajla!"; return(View("Index")); } return(View("Index")); }