问题
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