public class ExcelOperations
{
public List<List<string>> Read(string filePath)
{
OleDbConnection conn = new OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0; Data Source = " + filePath + "; Extended Properties = 'Excel 8.0; HDR=NO'");
OleDbCommand cmd = new OleDbCommand("select * from [Sheet1$]", conn);
conn.Open();
OleDbDataReader dr = cmd.ExecuteReader();
List<List<string>> data = new List<List<string>>();
while (dr.Read())
{
var obj = dr.GetValue(0);
if (obj == DBNull.Value) continue;
var shortList = new List<string>();
for (int i = 0; i < dr.FieldCount; i++)
{
shortList.Add(dr[i].ToString());
}
data.Add(shortList);
}
conn.Close();
return data;
}
}