Search code examples
c#excelodbcoledb

ACE OLEDB 12.0 property HRD=NO doesn't work


I want to get whole sheet with the standard headers something like "F1, F2, F3 etc."
But this is posible only if the first row is empty if the first row containe some text it is opeare in the header of the table. The option HRD=NO don't have any affect on this behavior and this is very strange maybe it is some bug ???

This is how look my connection:

string conn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\example.xlsx;
Extended Properties='Excel 12.0;HRD=NO;IMEX=1';

Solution

  • There is no HRD option inside connection string when using ADO.NET for Excel. Probably you want to use HDR option like this:

    string conn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\example.xlsx;
                    Extended Properties='Excel 12.0;HDR=NO;IMEX=1';
    

    The HDR option decides what the first column contains, if you're setting that to NO then the first column treated as data, otherwise it treated as column header (HDR=YES).

    Reference: ADO.NET provider for Excel - connection strings