This project has moved. For the latest updates, please go here.

How to Select data from excel using column header in closedXML

Aug 13, 2016 at 12:23 PM
Edited Aug 13, 2016 at 12:27 PM
Iam using this code for retrieve data from worksheet but i not able filter with column header in this
 var workbook = new XLWorkbook(filePath);
  IXLWorksheet ws1 = workbook.Worksheet(1);
 foreach (IXLRow row in ws1.Rows())
        {
            //Use the first row to add columns to DataTable.
            if (isRequiredHeader)
            {
                foreach (IXLCell cell in row.Cells())
                {
                    dt.Columns.Add(cell.Value.ToString());
                }
                isRequiredHeader = false;
            }
            else
            {
                //Add rows to DataTable.
                dt.Rows.Add();
                int i = 0;
                foreach (IXLCell cell in row.Cells())
                {
                    dt.Rows[dt.Rows.Count - 1][i] = cell.Value.ToString();
                    i++;
                }
            }
        }

It will return full columns, but i need only 2 and 4 th column data having name 'mobile' and 'pincode' how to get whole data for those two columns