Get a column from a search of a field

Aug 6, 2012 at 8:36 AM


I have a IXLTable composed of 2 rows, 1 header row and 1 row containing values.

What i would like to do is searching for a field name in the first row (the header) and then getting the column ( or ideally the cell right under the field just found).

There is a line of code in the documentation ("Finding and extracting data" part) but it doesn't work :

companies = companyTable.Rows()
                .Select(companyRow => companyRow.Field("Company Name").GetString())

The red part doesnt work as it gives me the followinf error.

(Error 1 'ClosedXML.Excel.IXLRangeRow' does not contain a definition for 'Field' and no extension method 'Field' accepting a first argument of type 'ClosedXML.Excel.IXLRangeRow' could be found (are you missing a using directive or an assembly reference?) 

Aug 6, 2012 at 3:08 PM

That piece of documentation was outdated. You should use the DataRange. A while back I changed the tables to behave closer to a regular range and then provided a DataRange that will behave more like a table (with fields and stuff).

            companies = companyTable.DataRange.Rows()
                .Select(companyRow => companyRow.Field("Company Name").GetString())