开发者

reading column header in excel file

开发者 https://www.devze.com 2023-03-02 08:47 出处:网络
I am reading data from excel file using OLEDB connection. But the problem is I can\'t read the column header.

I am reading data from excel file using OLEDB connection. But the problem is I can't read the column header. I开发者_Python百科 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.


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);
       }


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


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/

0

精彩评论

暂无评论...
验证码 换一张
取 消