I want to get the number of rows that are non-empty in an excel sheet. I am using asp.net and C#, and in my form I am uploading a simple excel file, with the number and names of column is decided by the user only (means the data column names are unknown). I am looking for a perfect way to get the number of excel rows that are not empty. The following code I am using gives a count of 78 for a list of rows having only 3 rows of non empty data (excluding the first row, as it is used for column name). Here is my code:
con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pathExcel + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';");
string cmdS = "SELECT * FROM [Sheet1$]";
if (con.State == ConnectionState.Closed)
con.Open();
OleDbCommand cmd = new OleDbCommand(cmdS, con);
OleDbDataAdapter adp = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
adp.Fill(ds, "MailingList");
DataRow dr;
dr = ds.Tables["MailingList"].Rows[0];
int intExcelRowCount=0;
// the following thing give me output as 78 but my sheet has only 3 records.
intExcelRowCount=int.Parse(ds.Tables["MailingList"].Rows.Count);
Any perfect way to do this?