reading column header in excel file

大兔子大兔子 提交于 2019-12-11 23:40:16

问题


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.


回答1:


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



回答2:


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




回答3:


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/



来源:https://stackoverflow.com/questions/5856440/reading-column-header-in-excel-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!