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/
精彩评论