Search code examples
c#asp.netexceloledbaceoledb

Get only specific columns from Excel (ACE OLEDB)


I am using ACE OLEDB to load an excel file into a DataTable.

I have a list of the columns I need to grab from the file (column names).

Problem is I couldn't find any working source on how to get only those specific columns from the Excel into the DataTable.


Solution

  • You can query columns like you would any other SQL sentence:

    SELECT [columnName1], [columnName2] FROM Sheet1

    columnName should be the value in the header of the column that you are trying to get.