With .Net's OleDb I try to import an Excel table in which the first row(s) can be empty. I want to keep the empty row in the DataTable to be able to map the cells to Excel-style cell names "A1, A2, ..." later. But the first line is removed, no matter what I do.
Excel file looks like:
- - -
ABC XY ZZ
1 2 3
4 4 5
Where "-" is an empty cell. (I have no influence to the import format.)
Simplified code:
string cnnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"file.xls\";Extended Properties=\"Excel 8.0;HDR=No;IMEX=1\"";
string mySheet = "Sheet1$";
OleDbConnection connection = new OleDbConnection(cnnStr);
DataSet Contents = new DataSet();
using (OleDbDataAdapter adapter = new OleDbDataAdapter("select * from [" + mySheet + "]", connection))
{
adapter.Fill(Contents);
}
Console.WriteLine(Contents.Tables[0].Rows.Count); // prints: 3
Console.WriteLine(Contents.Tables[0].Rows[0].ItemArray[0]); // prints: ABC
Any idea how to preserve that empty row?
ps: I found How to count empty rows when reading from Excel but couldn't reproduce it.