I have a situation where i need to skip first 3 rows and from 4th row - nth row i have to read. I tried few thing but was not successful - like reading all then writing into other excel and then removing first 3 rows.
Nothing worked out. can someone please help…Please find screenshot below:
I don’t know how applicable this solution would be,
but if you read all, you can skip first 3 rows by manipulating the table as an enumerable. dt1.AsEnumerable.Skip(3).CopyToDataTable
Read excel - with uncheck “add headers” option say dt1
Lastcount =Dt1.rows.count+1
Use foreach to loop through datatable
Rownumber=rownumber+1
Use if condition on one of column and compare row value with (name or emp id or skill or salary etc)
Here’s another concept, since your table has headers (you might want the headers as the columnheaders)
-Find the header row
-Find the last row
-use those values as your range
It would look like this:
Read Range of entire table // I'll store in dt1
headerRowNum = dt1.Rows.IndexOf( dt1.AsEnumerable.Where(Function(r) r(0).ToString.Trim.ToUpper = "NAME").ToArray(0) )
lastRowNum = dt1.Rows.Count
Read Range using new range with "AddHeaders" checked
// range: "A"+headerRowNum.ToString+":E"+lastRowNum.ToString
You may also select to use a dynamic column value instead of “E”, when then you would want to also store the last column letter like this: Convert.ToChar(dt1.Columns.Count+64).ToString
or something similar to that.
So, thought I’d just point out this other idea too
It allows you to use AddHeaders too, and dynamically will pull in all the data.
My suggestion would by to figure out which row the headers are on dynamically.
Using my previous post, you can store the header row.
Like this:
Read Range of entire table // I'll store in dt1
headerRowNum = dt1.Rows.IndexOf( dt1.AsEnumerable.Where(Function(r) r(0).ToString.Trim.ToUpper = "NAME").ToArray(0) )
Read Range using new range with "AddHeaders" checked
// range: "A"+headerRowNum.ToString