mucchar
mucchar

Reputation: 3

reading column header in excel file

I am reading data from excel file using OLEDB connection. But the problem is I can't read the column header. I am using

String sConnectionString1 = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" +"E:\\"+
                             Sourcefilename + ";" + "Extended Properties='Excel 8.0;HDR=Yes;Format=xls;'";

in connection string.. please help me out.

Upvotes: 0

Views: 8371

Answers (3)

Antony Thomas
Antony Thomas

Reputation: 3696

You can use OLEDB to connect and read from excel sheets. Here is a good example http://codehill.com/2009/01/reading-excel-2003-and-2007-files-using-oledb/

Upvotes: 0

varadarajan
varadarajan

Reputation: 514

Load the Excel in Dataset and Access the Column collection to get the ColumnName gives the Column header

       foreach (DataColumn dc in output.Tables[0].Columns)
       {
           Console.WriteLine(dc.ColumnName);
       }

Upvotes: 1

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174457

Calling GetSchemaTable on the SqlDataReader derived class returns a DataTable with a Columns property. This will give you the names of the columns.

Upvotes: 0

Related Questions