Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
[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); // Read first header content
               header2 = a.ElementAt(1); // Read Second header content
               header3 = a.ElementAt(2); // Read third header content
               header4 = a.ElementAt(3); // Read fourth header content
               break; // Break so that i should not read data other than header
           }
           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.
Posted
Updated 12-Oct-12 2:55am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900