Hi,
In Core MVC i am reading data from Excel, but there is a problem. Even though there is no row in Excel, it throws blank rows.
What is the reason for this and how can I prevent it. It just returns the filled rows.
For example, when there are 4 rows. When I check, 1 line or more than 1 line results, the data always comes null.
Controller
XLWorkbook workbook = new XLWorkbook(fileNameWithPath);
IXLWorksheet workSheet = workbook.Worksheet(2);
DataTable dt = new DataTable();
bool firstRow = true;
foreach (var row in workSheet.Rows())
{
if (firstRow)
{
foreach (var item in row.Cells())
{
dt.Columns.Add(item.Value.ToString());
}
firstRow = false;
}
else
{
dt.Rows.Add();
int i = 0;
foreach (IXLCell cell in row.Cells())
{
dt.Rows[dt.Rows.Count - 1][i] = cell.Value.ToString();
i++;
}
}
}
List<DusumDto> dusum = (from DataRow dr in dt.Rows
select new DusumDto()
{
StokKodu = dr["STOK KODU"].ToString(),
ArtikelName = dr["ARTIKEL ADI"].ToString(),
BeyannameNO = dr["BEYANNAME"].ToString(),
TicariTanim = dr["TICARI TANIM"].ToString(),
Karisim = dr["KARISIM"].ToString(),
Agirlik = (decimal)(dr["AGIRLIK"]),
Mensei = dr["MENSEI"].ToString(),
GtipNo = dr["GTIP NO"].ToString(),
Marka = dr["MARKA"].ToString(),
Artikel = dr["ARTIKEL"].ToString(),
KumasKodu = dr["KUMAS KODU"].ToString(),
//BirimFiyat = Convert.ToDecimal(dr["BIRIM FIYAT"]),
//ToplamFiyat = Convert.ToDecimal(dr["TOPLAM FIYAT"]),
//Adet = Convert.ToInt32(dr["ADET"]),
//KoliAdet = Convert.ToInt32(dr["KOLİ ADET"]),
}).ToList();
VM_Dusum dusums = new VM_Dusum();
dusums.Dusumler = dusum;