Search code examples
c#excelfileoledb

C# Reading an Excel file by column Index


I need to read an excel file using OLEDB by specifying column indexes. For an example I need to red data in Column A,B,C,AA,BC,ect... (the column indexes in Excel)

How can Ido that?

Thanks in advance.


Solution

  • Did you tried a query like this SELECT A,B,C,AA,BC FROM Sheet1$? Make sure you put Extended Properties="Excel 12.0;HDR=YES in the OLEDB connection string, it will help you to treat the first row as header.