Task
Import data from excel to DataTable
Problem
Some of Rows that does not contain any data are getting skipped and the very next Row that has data in the row is used as the value of the empty Row
In Excel Totally in have 37 Rows when i use openxml to convert excel to Datatable it skipped empty rows and read 29 rows only
WorksheetPart worksheetPart = (WorksheetPart)spreadSheetDocument.WorkbookPart.GetPartById(relationshipId);
Worksheet workSheet = worksheetPart.Worksheet;
SheetData sheetData = workSheet.GetFirstChild<SheetData>();
IEnumerable<Row> rows = sheetData.Descendants<Row>();
foreach (Row row in rows) //this will also include your header row...
{
DataRow tempRow = dt.NewRow();
int ko = row.Descendants<Cell>().Count();
for (int i = 0; i < row.Descendants<Cell>().Count(); i++)
{
tempRow[i] = GetCellValue(spreadSheetDocument, row.Descendants<Cell>().ElementAt(i));
}
dt.Rows.Add(tempRow);
}