In my project I had a requirement of reading excel sheet data and validate the same. Then store it in database. It is working fine, in this excel template row 1
is header and data will start from row 2
.
eg:-
Name Age Arabic Name Category
Jack 30 بيب A
var mem = from memRec in excelFile.Worksheet("Addition Form")select memRec;
Then I can get the details using memRec["Age"],memRec["Name"] etc.
This is working fine.
Now the client has a different template in which first 3-4 rows are merged with their logos and all. The header will be at row 4
and data will start from row 5
.
eg:
row1
row2
row3
row4 Name Age Arabic Name Category
row5 Jack 30 بسيب A
I tried below code to read this
var mem = from memRec in excelFile.Worksheet("Addition Form")select memRec;
it is not reading it and giving error because the heading is starting from row 4 only.
I don't know the range of data also because it depends on user filling data.
So I am unable to specify the worksheetrange.
Is there any way to specify the starting row to read the excel through Linq. Also once it is done can we specify the row as
memRec["Age"],memRec["Name"] etc.?
Edited
I used below code
mem = from memRec in excelFile.Worksheet("Addition Form").Skip(2) select memRec;
but when I tried to call memRec["Age"]
it is giving error saying no such column and columns available are Logo1,namecomp.
..etc.. this is the content of first row of the excel sheet
my excel sheet is like this now
row1 Logo1 namecomp place situation
row2 Name Age ArabicName Category
row3 John 30 يبي A
I don't want row1 as my column headers. The column headers are in row 2 and data start from row3.
Now when I try to read memrec["Name"] it is giving error saying that no such column header. Available column headers are Logo1, namecomp etc..
Please help me to solve this issue..