Hi all,
I am working on importing the data from the excel file, where i achieved data import from the excel using LinqtoExcel library.
But what I want is, need to read the headers alone from the excel sheet.
I used the below query to read the header content from the excel, but i want to know how many headers are there in excel sheet.
I place my code snippet for your reference.
[HttpPost]
public ActionResult impFile(FormCollection form)
{
var excel = new ExcelQueryFactory("C:\\Documents and Settings\\rk.prabakar\\Desktop\\test.xlsx");
var dataContent = from c in excel.WorksheetNoHeader()
select c;
string header1, header2, header3, header4;
foreach (var a in dataContent)
{
header1 = a.ElementAt(0);
header2 = a.ElementAt(1);
header3 = a.ElementAt(2);
header4 = a.ElementAt(3);
break;
}
return null;
}
Questions:
How can i get the count of header from the excel sheet?
How to pass a full path of the excel sheet to the above function?(i hardcoded the excel file path)
Is there any other way to achieve the count of header?
Any tips or tricks will be greatly appreciated.
Thanks in advance.